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

learn more… | top users | synonyms (1)

1
vote
1answer
26 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
27 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
38 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
19 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
57 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
52 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
34 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
50 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
41 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
123 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
45 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
31 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
22 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
19 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
29 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
197 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
32 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
38 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
226 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
34 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
votes
0answers
30 views

Delete string from all the files in the folder

I'm seeking for way to delete string from all files in the folder by the regular expression pattern. Need to delete not the whole string but just pattern. Need to delete the strings which looks like: ...
1
vote
1answer
21 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} ...
0
votes
3answers
284 views

How to delete html tags from a file using sed ?

I have a file that is mixed with both normal text I need and html-tags. I know that with REGEX it is possible to recognize html tags and with sed one can swap those for an empty string, but I do not ...
0
votes
1answer
45 views

How to find with grep lines that end in a certain string?

I know that to find a REGEX that ends in a certain string I have to write "string$". Although I tried the following variations of grep : cat foo | grep "string$", cat foo | egrep "string$", grep -E ...
0
votes
2answers
59 views

What regular expression in grep searches for strings of three same letters in a row?

I have a text file and I am using the grep command with a regular expression to get only the lines which contain three same successive letters, e.g.: aaa bbb ccc ddd What regular expression do I ...
6
votes
3answers
306 views

How do I use the regular pattern operator {m,n} in grep?

I have a text file, from which I need to select only those lines, which include the string "tt". So I tried this on the command line: grep "t{2}" textfile Allthough I know the textfile contains ...
4
votes
3answers
91 views

How can I find and replace only if a match forms a whole word?

My script is: n="y" while [ "{n}" = "y" ] if [ $n == "n" ]; then break; fi echo "n is $n" do read -p "Enter the word to find = " word read -p "Enter word to replace = " replace ...
0
votes
1answer
36 views

Regex for matchng anything between parenthesis

I have the following regex so far: printf "this is (test.com)\n" | grep -Po '(?<=\().*(?=\))' The above regex will print the desired output, which is test.com As far as I am adding new ...
0
votes
1answer
40 views

What is the Difference between Regex `[]*` and `[]+`?

I started learning regex recently. I know that * modifier means match 0 or more times while + modifier means match 1 or more times. However when you use these modifiers with square brackets, how ...
3
votes
2answers
65 views

How can I exclude a string using a regular expression?

I have this file named test: http://edge.sharethis.com http://edge.sharethis.com https://timetosa.com http://timetosa.com https://webtest.es holahttp.com timetosa I want a expression that excludes ...
1
vote
1answer
54 views

sed regex not working for hidden characters

I have a list that has for some reason got some non alphanumeric characters appended to the end. I would have thought it would be a simple case of running : sed 's/[^A-Za-z0-9]$//' To replace ...
0
votes
3answers
93 views

Using sed to remove digit separation commas enclosed in quotes and quotes itself from CSV? [duplicate]

How can I can use sed to remove from before-last column the group digit char comma and quotes itself? Please note that in the sample below the target column is not contained in double quotes. ...
2
votes
4answers
72 views

Substitute all occurrences of pattern with first matched group

I have to go from this: text match$something_here and match$xxx blablabla text match$something_else_here and match$xxx blablabla ... to this: text match$something_here and match$something_here ...
0
votes
1answer
24 views

Coordinates X237595Y81600 to X2375Y8160

I have create a gerber file and it has lines inside which look like this: X90095Y15350 X100095Y15350 X110095Y15350 X120095Y15350 X120095Y25350 X110095Y25350 X100095Y25350 X90095Y25350 X80095Y25350 ...
3
votes
3answers
280 views

Why awk understand FS=“*” but not for FS=“-*-”?

I got a test file, its content is: a -*- b I used awk 'BEGIN {FS="*"} {print $2}' test, it prints out - b Correct! But when I use awk 'BEGIN {FS="-*-"} {print $2}' test, I got: * I know that ...
1
vote
0answers
29 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 ...
0
votes
1answer
32 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
2answers
87 views

sed to replace a word from a file with the contents of another file? [duplicate]

I have two files file1 & file2. Contents of file1: Text1 Text2 Text3 Contents of file2: Sample1 Sample2 Sample3 I would like to replace the word Text1 from file1 with the contents of ...
1
vote
1answer
35 views

Retrieving words before certain characters without having to use Perl

I have where clauses for SQL queries in text form, and I'd like to extract the column names from them. The clauses can contain conditions like col_1 = 'Spruce' and col_2 in ('Argentina', 'Cameroon'). ...
1
vote
4answers
55 views

Search and replace two words with ex command

I want to search and replace 2 words with 2 other words with one g/.../s/.../.../g command. For example to replace word 'car' with 'truck' and 'cat' with 'dog' with one ex command in Vim.
2
votes
2answers
51 views

How to search many files with regular expression and output matches to lines in a new file?

I have 1000's of source files and I would like to find all text that matches a regular expression and then output each match on its own line in a resulting text file. For instance; // a.cs string ...
1
vote
1answer
21 views

some POSIX Bracket Expressions not working

For example when I'm trying to find and replace something using g/[:digit:]/s/1/2/g Vim showing error: Pattern not found: [:digit:], while the string contains digits. Following POSIX Bracket ...
0
votes
1answer
78 views

regex find replace strings starting or beginning with backslash

I have a compilation album in my music library that has song titles in the form of ARTIST/ TITLE, which is making it really difficult to cp or mv these files because of the slash. So I'd like to ...
3
votes
2answers
161 views

Capture in shell variables the arguments after a command (between brackets)

Suppose I have a file that contains, among many other things, \command{arg1,arg2,arg3} (arguments been paths, expressed with /, ., characters and numbers) But that a user can as well call it ...
0
votes
1answer
30 views

is there a way to see a listing of packages ONLY from Debian-experimental?

I am on Debian testing/Jessie and I have debian-experimental as well as in my /etc/apt/sources.list. So I am looking to list packages in two ways :- a. List all the packages which are in ...
1
vote
2answers
38 views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n ...
1
vote
4answers
236 views

Regex pattern search for alternating character case

How would I pipe the ls through grep to have an alternating character case, as output? For example: I have files (1) aAbBaBbA, (2) bAbBaA, (3) bbAb,(4) AAaBbAa,(5) BBBaaa, and (6) aBaB. I want to ...