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

learn more… | top users | synonyms (1)

1
vote
2answers
54 views

Strange “apt-get purge” behaviour with regEx

I'm running Debian (jessie) and following this question, I followed the first answer suggestion to install that packages running sudo apt-get install gtk2-engines-* gtk3-engines* That did not ...
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 ...
0
votes
1answer
32 views

Bash group matching

I am using bash 3.1.17(1)-release and script below. It doesn't show group match for input i.e. 4fwk2_dev 2fwk5_dev echo $FWK FWK_REGEX="/(\d{1,3})fwk(\d)_dev/" if [[ $FWK =~ $FW_REGEX ]]; then ...
0
votes
2answers
35 views

sed to change dns log string format

I want to use sed to change the following text: (3)www(5)first(3)nth(6)domain(3)com(0) to: www.first.nth.domain.com Can each group between the parenthesis separators be captured and then ...
5
votes
0answers
58 views

Perl one liner to find words longer than 63 characters

I have a number of xml files containing sanskrit texts to be converted to tex. Latex has a maximum of 63 characters per word for its hyphenation to work, everything longer than that will not be ...
1
vote
1answer
31 views

pattern regex for apache rewrite rule

I have the following pattern on a few thousand lines I will like to use regex to convert to what I want RewriteRule ^/omg/deadly-venom/?$ http://www.example.com/omg/deadly-venom [L,NC,R=301] ...
0
votes
2answers
54 views

Find all folders starting with number range

How can I find all folders starting with a value in the number range 500 to 899? I just need to list them in a file. Additional informations: Maxdepth 2 Examples of folder names: ...
1
vote
1answer
47 views

Is there any text search tool preloaded with well-known regexes?

I would like to know if there is any command line tool to search text files preloaded with some well-known regexes (IP, email, date, path, url, xml tags, etc) so you could do something like: grep -A ...
3
votes
1answer
70 views

How to optimize 'grep'-and-save?

I want to know on which node my calculations were running on our cluster in case the node crashes and I get no files back to know on which node I have to search. For that case I wrote a little script ...
-1
votes
3answers
71 views

How to catch with RegExp first word with different first symbol in it using ed text editor

I have shell command: printf '/^PermitRootLogin/\nc\nPermitRootLogin no\n.\nw\nq\n' | ed -s /etc/ssh/sshd_config And I need catch #PermitRootLogin like PermitRootLogin but not commented paragrath ...
1
vote
1answer
36 views

List lines that consist of a single non-vowel character

I need help with listing lines that consist of a single non-vowel character. I got this: ls | grep -nv '[aeiouy]' file But this doesn't give me a single character. How do I get just a single ...
0
votes
1answer
32 views

find lines that don't end with 'rpms' with sed

I would like to find lines that do not end with 'rpms' with sed in Linux. I have tried below: sed -ne '/?!(rpms$)/p' But unfortunately, it is not correct.
3
votes
6answers
170 views

Add quotes and new delimiter around space delimited words

I have the following string y10_zcis y10_nom y10_infl y20_zcis y20_infl y30_zcis I would like to transform this to "y10_zcis", "y10_nom", "y10_infl", "y20_zcis", "y20_infl", "y30_zcis" I ...
3
votes
1answer
89 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 ...
6
votes
4answers
228 views

find: list all directories except those with numbers in their names and their children

I am running the following to find all directories without a number in them (not including the original path): find /path/2/directory -type d -name '[!0-9]*' The problem is that it finds ...
1
vote
1answer
51 views

multi line awk regular expression [duplicate]

Consider text.txt with this content: blablabla &&&key word&&& I want all these text and numbers 123 and chars !"£$%& as output &&&key word&&& ...
0
votes
3answers
40 views

Extract Strings from Web Log file

Given a file containing web access logs for a YouTube video, every line is a hit and is in the format. 62.172.72.131 - - [02/Jan/2003:02:06:41 -0700] "GET /random/html/riaa_hacked/ HTTP/1.0" 200 ...
0
votes
1answer
53 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 ...
-2
votes
2answers
60 views

regular expression's $ character

I know when I use $, it means characters before $ must be shown at the end of the string. But, I don't know difference between the tests given below, when the variable a is integer: [[ a =~ ...
1
vote
2answers
36 views

Egrep back referencing not working

I have trying top back reference the first captured group in the below command: $ ls -lR | egrep 'd(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))---' ...
0
votes
3answers
54 views

sed backreference: get each line and append it to end of line

I have a file with following content: $ cat -n w 1 Smith John 12345 jsmith 2 Jones Robert 23456 rjones 3 Green Ralph 34567 rgreen 4 Brown Fred 45678 ...
0
votes
1answer
31 views

pattern regex for apache rewrite

I have a bunch of URLs counting to thousands i need to redirect and there are thre main patterns in URL first pattern There is a dash - starting the title url and want to remove that dash e..g ...
0
votes
1answer
48 views

Grep: Why escape modifiers?

By modifiers I mean the following: -\{m\} exactly m repetitions of previous character - \{m,\} at least m repetitions of previous character - \{m,n\} any number of repetitions of prev char between m ...
1
vote
0answers
61 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
2answers
59 views

Why does perl regex find pattern \\label\{.*?\} but not \\ref.*?\} or \\autoref\{.*?\} in TeX Files?

I am using perl to parse many multilingual text files. I need to change the text between two patterns: Desired Changes For example, the English original version looks like this: \label{whatever} ...
0
votes
1answer
23 views

Piping difference of grep -c's with different regex to bc

I need to find the number of words in a file (1 word per line) that do not contain some set of letters. To do this I want to take the difference of grep -c '.' <file> and grep -c ...
0
votes
2answers
109 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
29 views

Meaning of `expr “hello” : “\([a-z]*\)”`?

I need a explanation of why: $test=`expr "hello" : "\([a-z]*\)"`; echo $test would print out hello, where as: $test=`expr "hello" : "hel"`; echo $test would return the number of characters ...
0
votes
1answer
29 views

regex to remove last four characters

Is there a way I could eliminate the last four characters with regex in the below one line script as I convert .wav files into .mp3 files. As of right now my single line script produces files ending ...
0
votes
1answer
45 views

How do I remove a line if it begins with a . or a > using sed?

For the life of me I can't get this to work properly (forgive me if this is a trivial question). I have a text file that have lines that begin with either a period, ".", or a right arrow, ">". I need ...
2
votes
1answer
44 views

Regex matching on awk in command line

I'm trying to get the filename from unrar command verbose and deleting them all through command line. The unrar command output is similar to this: Extracting BucketSort.cpp ...
0
votes
2answers
32 views

sed + add comment to IP - only if IP is matched exactly

my target is to add "#" to the IP's with sed, But Only if IP is matched exactly!!! for example: sed 's/72.16.90.12/#72.16.90.12/g' /etc/hosts more /etc/hosts 72.16.90.121 host1 ...
1
vote
1answer
42 views

sed + update 4 different IP's in hosts file in one sed command

how to run the follwoing sed command in one command line? sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts ...
5
votes
4answers
636 views

Delete folders whose name has 4 digit numbers two times

I want to delete folders using regexp in a Mac terminal. 0129_0140 (no delete) 0140_0140 (delete) 0150_0160 (no delete) 0170_0170 (delete) I just want to delete folders such as 0140_0140 , ...
0
votes
2answers
50 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. ...
1
vote
3answers
130 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
0
votes
2answers
30 views

Joining certain lines of text together before modifying them

I have a cricket commentary like - 0.3 Richardson to RG Sharma, 2 runs, gentle, non-swinging length ball on off, Rohit seeks to pick it up. Hit high on the bat and spooned over the returning Mitch ...
0
votes
2answers
36 views

find command from regular expression

I have question about regular expression. There are two commands. find / -regex '.*[^-_./0-9a-zA-Z].*' find / If I'm right, these two commands should output same results. Because, the first ...
2
votes
2answers
50 views

vim find and replace around a string

In VIM, if, for example, I have the text http://a.com http://b.com is it possible to find all lines (the whole line) and replace it with something before and after it, such as: <a ...
2
votes
5answers
552 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
-1
votes
3answers
72 views

scp a file to multiple folders

I wanted to scp file.txt to remote box my-remote-vm-1 In my-remote-vm-1 there are two folders conf-1-ver-2,conf-2-ver-2. The integer part in the folder name can go from [0-9]. What would be the best ...
1
vote
2answers
120 views

Postfix: Remove References to Server Software

Every time my postfix servers sent emails at the destination the emails headers include the following: by suppaserver.example.dev (Postfix) with ESMTPSA id 79D412E1A3A How can I remove the ...
1
vote
3answers
36 views

How do I replace this pattern with a newline inside it? [duplicate]

If I have a text file with this content: someline <!--\ file first read on 2015/01/11 And I want to delete <!--\ and everything until what comes after "on", how do I do it? The ...
3
votes
3answers
79 views

backreferences in `rename` regex

I have A LOT of files named "bar_foo.txt" in a directory, and I'd like to rename them to "foo_bar.txt" instead. In sed and vim the regex to to this would be something like ...
1
vote
1answer
44 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
1
vote
1answer
46 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
8
votes
2answers
67 views

What does [[.ch.]] mean in a regex?

Alternate title: What is a "collating sequence" or "collating element" in a POSIX-compliant regex? I found the exact technical definition in Section 9.3.5 of the POSIX specs, as item #4 in the list, ...
0
votes
2answers
146 views

perl: Replace string in file with double quotes

Following up question from http://unix.stackexchange.com/a/254637/18887 I have the following string in a bash variable This rule forbids throwing string literals or interpolations. While JavaScript ...
2
votes
2answers
76 views

sed to match pattern between matching curly braces

From a pattern such as [string 1]{string 2} I want to extract string 2, the string between the last pair of matching curly braces -- that is delete [string 1] and the open { and close }. My ...
4
votes
2answers
89 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 ...