Regular expressions are a means of matching a pattern of characters within a string.

learn more… | top users | synonyms (1)

1
vote
4answers
158 views

Regexp on data flow

I want to test if in my data flow, there is something, and do an exit code. I use gammu monitor, which provides a data flow, for example : [root@MYSERVER ~]# gammu monitor Press Ctrl+C to break... ...
0
votes
3answers
212 views

Finding and replacing text inside awk block

I want to find and replace a value inside awk block. Here is a sample input file to my script P1 10,9:11/18013013582 ,10:1 ,167:0 ,487:5/E.164 11,9:15/310410532169026 ,10:60 ,167:0 ,487:4/IMSI 12,18:...
4
votes
2answers
93 views

BSD sed: Replace only the Nth occurrence of a pattern

Using BSD sed; How can I perform the following substitution?: Before: hello hello hello hello hello hello After: hello world hello hello hello hello In other words; how can I replace only the ...
2
votes
2answers
536 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
1
vote
2answers
56 views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
0
votes
2answers
115 views

POSIX regular expression match on first occurrence of string

I have bash script I only want to support long options ("--option"). An --option can optionally have one or more arguments. All words (anything delimited by whitespace) up to but not including the ...
0
votes
2answers
56 views

Collecting network information

I need to collect information about the network usage of each process. Nethogs presents the data I need in real time, I am trying to save the output to a file in order parse it and plot the data. ...
0
votes
2answers
33 views

finding how many options ls have

Just for practise i want to find out how many options does ls command have. I have written following piece of code man ls | grep -o -i '\-[a-z0-9]$' Why does this piece of code only printed -C and ...
0
votes
2answers
73 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...
0
votes
2answers
162 views

Use multiple commands in sed to insert text after string with special characters

I am having a little trouble trying to do a search and replace using sed in a config file. I want to use multiple commands using the -e option to do the following. Step 1: find the first occurrence ...
0
votes
2answers
622 views

How to match and replace an attribute value inside a tag

I am trying to replace the value of following node using sed command. <KeyValue key="EMPTY_SEARCH_CRITERIA" type="String" value="CS_CODE" comment="Configured empty search criteria."/> I am ...
0
votes
2answers
417 views

How to make a script to move files with find and regex

Im trying to make a find regex script so i automaticly can copy files to specific directory. find . -regex "*test.*s01e([0-9][0-9]).*" -exec cp {} /storage/tv/test/s01/ \; Made this script, dont ...
5
votes
1answer
133 views

file(1) and magic(5) : prioritizing a result

My question follows that one: file(1) and magic(5) : describing other formats . I want to describe a FASTA sequence ( http://en.wikipedia.org/wiki/FASTA_format) It could be a DNA sequence (with only ...
4
votes
1answer
91 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
1
vote
1answer
89 views

LFTP exclude file extensions

I am trying to mirror directories with lftp but I don't want to download filetypes that are notoriously large like .mp4 and .swf. But I am having trouble with the regex - and seeming like the exclude-...
0
votes
1answer
31 views

Does find Command Do Match For Regexp Because Of Implementation?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and jtobdops.02.cer....
0
votes
1answer
71 views

How can I use part of match in Regex to generate filename of action?

I am using CentOS6.5 that include rsyslogd v5.8.10 There are 20 process program in my server.I want to receive logs use rsyslogd and hope to store in different log file according identity of process ...
0
votes
1answer
180 views

SED find and replace element in filename with incremental values

A sample filename is Sample-0.0.1-SNAPSHOT.jar (result of a maven build in jenkins). My goal is to run a shell script that executes on failure and what that script does it adds incremental numbers to ...
0
votes
1answer
27 views

subtract dates from two files for same process

I have initiated 50 processes and in one file "say start_time", I have stored when process was started and in another file "say end_time", I have stored when process finished. files are like below - ...
0
votes
1answer
462 views

logstash regex match in if condition

In logstash filtering, I have multiple tags setup based upon different error conditions and all the tags has a prefix, something like "abc:" In the output, I want to send email based upon just "abc:*"...
0
votes
1answer
165 views

Use sed to only replace namespace in an element that has a parent element with a given attribute value

I want to replace the namespace in an xml file using sed (I've given up trying to do it from ant, where it is required). The main issue is that that there is a repeating list of elements - not all of ...
0
votes
1answer
45 views

Emacs: query-replace prepend text to the found string

The scenario is that I am trying to append a new class to all the style declrations in my css file. So .oldclass{ float : left; } should change to .newclass .oldclass{ float : left; } The ...
0
votes
1answer
455 views

Sed with angle brackets

This works sed 's/[[:space:]]*<default>false/XXX/' Why does prepending a > make it fail sed 's/>[[:space:]]*<default>false/XXX/' escaping the > does not help either. In ...
0
votes
1answer
94 views

How can I use gsub with a pattern? And how to tell it which file to awk?

I've read here that I can replace the values of all columns containing a particular text using awk -F'\t' -vOFS='\t' '{ gsub("CC", "C", $1) ; gsub("AA", "A", $1) ; print }' But where do I tell awk ...
-1
votes
1answer
75 views

SMTP log anonymize script

I have a SMTP log with records in the format below: 6,222.3.4.5,3040,100.2.3.4,25,UNKNOWN,0,1,……,9337bc-929a-34c0-29a8-b3a89c834b29 ,protocol,SMTP ,745663746,STATUS-COMPLETE ,VALID 6,222.3.4.5,...
4
votes
0answers
61 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an exploit?...
3
votes
0answers
217 views

What types of regex DO support (e.g.) negative lookbehind?

Bash on GNU: I am using a collection of find commands, most of which employ -regex to do their matching. Each time I try a different feature in my regex I have to cycle through the values for -...
2
votes
0answers
380 views

Bash regular expression comparison fail for hex byte \x01

Bash regular expression fails to compare correctly for $'\x01' when End-Of-String char $ is used. All other byte values (seem to) compare correctly. Using GNU bash 4.1.5(1). Is this a bug, or is ...
1
vote
0answers
69 views

Bash - Regex to match tuples of numbers

I want to check if a string that has been written to a variable in bash via the read command is a tuple of two numbers. To my knowledge, this should be possible with if [[ "$input" =~ "$regex" ]]; ...
1
vote
0answers
172 views

what is the correct regexp for mysql filter in fail2ban?

I use the default filter file /etc/fail2ban/filter.d/mysqld-auth.conf for fail2ban service. But there are some errors in file /var/log/fail2ban.log as: Found a match for '150815 10:42:54 [Warning] ...
1
vote
0answers
64 views

What is SELinux's regex type?

I'm trying to locate all files on my system matching an SELinux file context (fcontext). These contexts are specified using some regex, and I'd like to use find -regex ... to the same effect. However, ...
1
vote
0answers
158 views

Need .htaccess Rewrite Rule To Remove Trailing <br%20/>

I have links that for some reason have a trailing <br%20/> and I don't know where they are coming from to try and fix them. So I need a general rewrite rule to remove them so the links won't ...
0
votes
0answers
30 views

shell scripting using sed

I want to compare specific string surrounded by alphanumeric and some special chars in file. For example: 5efa4083-7157-437a-ab9a-652ced2fc2ea;: AAA :;5efa4083-7157-437a-ab9a-652ced2fc2ea;BBB I ...
0
votes
0answers
28 views

What does the “pipe” command do in mailx?

When using the mailx command line utility, there is a command called pipe listed in the man page (although not visible when using the help command). What does this command do? I want to be able to ...
0
votes
0answers
26 views

How to match Markdown Setext headers in in exuberant ctags

I am working on a language definition for pandoc markdown in ctags. However, I have problems matching Setext headers in the regex which are defined by multiple = or - in a new line under the header ...
0
votes
0answers
48 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
0
votes
0answers
15 views

UnionFS with filtering to determine default save location

I'm wanting to set up a UnionFS mount which will save all files/directories matching a certain regexp (or similar pattern-matching system) to one location and all other files/directories to another ...
0
votes
0answers
115 views

Need help with a regular expression with calibre

I'm actually in trouble about some regex in order to import books properly with calibre. Hopefully someone more experimented than me will have time to help... My book's names (entries) are in this ...
0
votes
0answers
50 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
0
votes
0answers
41 views

Regex for a non-fixed pattern

I am trying to come up with the right regex (compatible with python) that would match a file that contained sample input as follows: On the third day of Christmas my true love sent to me: three ...
0
votes
0answers
128 views

SED: print entire paragraph for specific pattern while loop

I find partial answer about my problem on this question but i still have trouble. I need to use a variable as a pattern for the sed command in a loop sed -e '/./{H;$!d;}' -e 'x;/'$var'/!d;' The ...
0
votes
0answers
71 views

SED and regex expressions… addr1 and addr2

How can I use sed to match 'addr1' and reuse it again in 'addr2' field? #Ex.: echo "12a34" | sed 's/a/#bcd/g' # 12abcd34 #\# = match addr1
0
votes
0answers
50 views

egrep for specified strings and newline

I receive a prespecified list of strings. In a number of textfiles (example below), I want to search for strings, that do not start with one of the strings in the list. From time to time, a blank link ...
0
votes
0answers
483 views

how to exclude range of numbers using regular expression

I'm trying to write a regular expression in order to cover all numbers starting with 1809 and excluding some ranges: Ranges needed to be excluded Starting with 1809 and followed by: 201,203,205,...
0
votes
0answers
40 views

To visualise systematically look-behinds

I am using Regexr to visualise my regexes now. I need look-behind but Javascript does not support it, example code here. The project code base seems to be dependent Javascript (NodeJS) in Github. I ...
0
votes
0answers
189 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...