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

learn more… | top users | synonyms (1)

3
votes
1answer
12 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...
2
votes
1answer
32 views

grep with regular expression

I want to match all the lines that are of the below pattern in a file using grep. Abc::xyz() [18-Feb-15 12:09:16] I came up with below regex with grep , but it is not returning match. Please help ...
4
votes
4answers
286 views

How do I extract parts of a string to variables?

I have a line from some file like this: attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks... I want to extract the 512^3, 16^3, 32^3 and 800 four ...
1
vote
1answer
26 views

sed exception handling of escaped characters

I want to delete anything that follows a % to the end of the line. Using cat /tmp/foo.txt | sed 's/%.*$//' works great with one exception: I want to ignore any escaped percent signs \%. So with ...
2
votes
1answer
41 views

Using fixed strings in regular expressions?

I am writing a bash script which accepts a list of CSV files as arguments and outputs e-mail addresses only found in the first file. To accomplish this, for each record in the first CSV file I look ...
1
vote
1answer
80 views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
2
votes
2answers
35 views

Perl non-greedy regex matching more than it should

I have the following text from which I need to remove some wdiff output. text='Иса Мәсіхтің елшісі Петірден [-(-] осы күнәкар дүниеде [-)-] жат жерлік болып, Понти, Ғалатия, [-Қападоқия, Азия және ...
0
votes
1answer
46 views

Bash detect ascii art [closed]

For bash script, is there a easy way to detect if a text contains ascii art? An example of ascii art:
2
votes
0answers
59 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 ...
0
votes
1answer
34 views

What is the email matching regex in basic regex for grep?

I created a text file and put some email addresses in it. Then I used grep to find them. Indeed it worked: # pattern="^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,}" # grep -E $pattern regexfile but only as ...
-3
votes
0answers
38 views

Regex: match word in line 1-3 times

My question is about regular expressions and searching for text. I need to search for all lines in text that contain one ceratin word, let's say "cat", one, two or three times.
0
votes
1answer
33 views

Vim: Count all occurrences (including multiple on the same line) of char or word

I try to count all occurrences of a char or word in a file with Vim. This means multiple occurrences of the same word in the same line should be taken into account as well. This has been discussed in ...
0
votes
1answer
22 views

Interactive less search with wildcards [duplicate]

I'm using less to view a large file and I want to search for a pattern with wildcards — e.g., " x 1??" where ? is any character. Does less support that, and if so how would I do that ...
1
vote
1answer
40 views

Find only in directories n levels deep

I use this command to find and run all istances of wp-cron.php I have for each site I have: find /var/www/ -name 'wp-cron.php' -exec php -q "{}" \; Since my websites tree is: ...
9
votes
3answers
671 views

Strange behaviour of “ls -a | grep ^\.”

I wanted to list the content of a pwd and display only file starting with dot. I tried ls -a | grep ^\. but I cannot figure out why the output contains also the files which do not start with dot. For ...
0
votes
2answers
32 views

Vim: Substitute based on another match in the line

I have rather large files in which I need to substitute NX for N1 but only if the line already contains NX as a pattern. So far I do it manually by first searching for occurrences of NX with: /NX ...
1
vote
3answers
131 views

How to perform grep onto the output of ldd properly ?

# ldd /usr/bin/ffmpeg linux-vdso.so.1 => (0x00007ffffc1fe000) libavfilter.so.0 => not found libpostproc.so.51 => not found libswscale.so.0 => not found ...
5
votes
5answers
358 views

How to replace a word with new line

I have a text file with following data and each row ends with |END|. T|somthing|something|END|T|something2|something2|END| I am tryig to replace |END| with \n new line with sed. sed ...
3
votes
5answers
286 views

How to grep the n-th substring between given delimiters?

Let's say we have a string and its delimiter is ?: Leslie Cheung April 1 ? Elvis August 16 ? Leonard Nimoy February 27 I know how to grep the first substring between delimiters: echo $above_string ...
1
vote
1answer
48 views

Pattern matching and removal of that pattern using sed

I have 2 files with the following names: File 1: RvA_X-IRB-bil-CA101-0+010000-20150327212332-055582-P File 2: RvA_X-IRB-bil-CA101-1+020000-20150327212332-055582-P I am using this command to match ...
0
votes
3answers
41 views

grep log lines of a specific id request

So, I have the following log sample: 2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1 2015-03-30 ...
1
vote
2answers
47 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
0
votes
4answers
40 views

AWK print regex pattern

I am trying to print a regex pattern for the following piece of mail log. In particular I am trying to get the ID between the square brackets (see the second line for reference). Mar 29 03:48:13 ...
1
vote
2answers
87 views

regular expression to extract information in shell script

I would to grep certain parts of some shell command output in the shell script: $ uname -r >> 3.14.37-1-lts Where I just need the 3.14.37. And also for the shell script variable VERSION that ...
-1
votes
1answer
40 views

Is it possible to get static backreference with grep?

I try to match a a group twice in multiline. grep -Pz 'Source: (?<group>.*/).*\n.*\n.*\n.*\k<group>|$' it work except one major problem - it doesn't, \k<group> search for .*/ and ...
3
votes
3answers
108 views

Shell test to find a pattern in a string

I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path. if [[ $line =~ ...
1
vote
1answer
32 views

Bourne shell: ignoring certain kinds of stdin

I have a program that is currently working, but I need to modify it to ignore some stdin that is not fitting for its correct function. Right now, to run the program: printf "1\n3\n5\n" | sh prog The ...
0
votes
1answer
30 views

Using regular expressions to search a word list. Finding 2 letter words instead of 3. Why?

I am studying regular expressions and I am stumped. Here is my process so far.... I downloaded this file. wget http://www.mieliestronk.com/corncob_lowercase.txt mv corncob_lowercase.txt words.txt ...
0
votes
1answer
52 views

How to search mail logs effectively with `RegEx`

I was looking for some advice and examples on searching mail log effectively Suppose situation is like this -------- Forwarded Message -------- Subject: Fwd: Re: Notice of Allowance Date: Fri, 13 ...
2
votes
3answers
50 views

Regular expression that ignores certain characters

I need to find a regular expression, that ignores certain characters for usage in the bib2bib tool. For example: I need to find any occurence of the word "muller". But also a string like ''Hello, ...
0
votes
2answers
22 views

How to use variables in substitution with vim regular expressions

I have a big file that contains among others serveral lines of the following form: USet07-1 USet07-2 USet08-1 USet08-2 . . . USet22-2 . . . I want to remove the hyphen/dash - from these strings in ...
1
vote
2answers
90 views

Pages don't get blocked with Squid over HTTPS

I have set up Squid to block pages on my own system (i.e not on a network), and I'm trying to get SSL to work with page blocking. To this end, I've set up ssl-bump and installed the certificate to my ...
1
vote
1answer
58 views

Problem with sed substition in multi-word regex

Take this simple example: echo "20150310 21:12:01.846338::: <?xml version="1.0"?><Haystack><Event " \ | sed 's/^\(.\{24\}\)::: \(<?xml.*><Haystack\|Foo\)>\(.*\)/\2 ...
0
votes
1answer
39 views

effect of [0-9]* in a regular expression

What is the function of [0-9]* in the following statement, which will write all lines that start with an even number, followed by a space, to the file even: sed -n 's/^[0-9]*[02468] /&/w even' ...
0
votes
1answer
20 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
2answers
67 views

Regular expression for excluding data within a certain range

I want to remove all the IP addresses which are of the format 10.20.30.* and whose last 3 digits fall in the range 0 to 200 and move all the remaining IPs to a new file. I've put the IP list to be ...
0
votes
0answers
52 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
5answers
132 views

To remove \n but not \n\n

Data 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b 292. Ipsun A) Apex B) hello b 289. He A) hu B) Ha C) He The right answer is: 1) Ab 2) Abc 3) ...
1
vote
1answer
49 views

Searching file for string surrounded by two other known string?

Question title may be kinda vague, but heres what im attempting to do. I have a html file locally on my server which is changing fairly regularly. It has multiple occurrences of: <p>Jumble of ...
1
vote
1answer
34 views

how to modify matches to a regular expression with sed or another tool?

I need to manipulate text that's in a file. I need to append a right parenthesis – ) – after every number that's preceded by a comma – , – e.g., ,4   ➜ ,4) ,15 ➜ ,15) I am struggling to find the ...
0
votes
2answers
29 views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
0
votes
0answers
11 views

use php variables for awk regex commands [duplicate]

trying to implement autosuggest using php. autosuggest list generated using awk $input= $_GET["term"]; $suggest=array(); exec('awk \'BEGIN{FS=","}/.$input./{print $2,"-cost-",$1}\' ...
1
vote
0answers
25 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, ...
0
votes
1answer
31 views

Printing out range of a pattern with awk

Im trying to print out a section of a txt file using awk. Basically I want to print out the paragraph in the a txt file that begins with certain words all up to a blank line.Here's what I have so far: ...
1
vote
3answers
286 views

Grep all string which do not starts with number(s)

I'm looking for grep to show all characters which do not starts with numbers. I have done something like this: grep -v '^[1-2]*[a-zA-Z]?' -o but it do not work. Do you have any idea for some reg ...
0
votes
0answers
33 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
1answer
39 views

What is the meaning of (^| )ABC( |$) as an extended REGEX ?

I came here across the command grep -E '(^| )ABC( |$)' file1 I am confused how to interpret the regular expression therein, because I know the ^ and $ character as beginning and end signifier, but in ...
2
votes
1answer
253 views

How to grep exact word with only space as word separator

For Example: I have file like following: AA ABC-AA-AA AAA ABC-AA ABC.AA ABC AA ABC.A AA If I use grep -w "ABC" file1, I am getting all the lines. But I should only get 3rd line: ABC.AA ABC It is ...
0
votes
1answer
38 views

How to change a single line in multiple files [duplicate]

I have ~750 .php files in the same directory that contain the line include("path/to/file.php"); I would like to change this line in every file to require_once("path/to/file.php"); What would be ...
1
vote
1answer
25 views

Why is logcheck reporting successful Horde logins?

I'm running Ubuntu 14.04 LTS server and use logcheck to report log messages. I have the logcheck-database installed which contains a horde3 ignore file for the server: ^\w{3} [ :0-9]{11} ...