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

learn more… | top users | synonyms (1)

0
votes
1answer
24 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
157 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
29 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
36 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
193 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
23 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
24 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
14 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
265 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
39 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
56 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
290 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
77 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
31 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
39 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
56 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
40 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
67 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
70 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
23 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
271 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
25 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
27 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
71 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
31 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
45 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
46 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
62 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
140 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
26 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
36 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
223 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 ...
4
votes
3answers
45 views

How to select first occurrence between two patterns including them

How can I select first occurrence between two patterns including them. Preferably using sed or awk. I have: text something P1 something content1 content2 something P2 something text something P1 ...
1
vote
1answer
41 views

How can I use regex to extract the text following two conditions into a variable?

I'd like to extract a setting for a given host in the ssh_config file and put it into a variable. Host mysite HostName 123.1.1.1 User myuser Port 13245 GSSAPIAuthentication no ...
0
votes
2answers
37 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 ...
2
votes
2answers
42 views

Group matching with grep includes extra characters

I wanted to extract some text with regex in bash, so I decided to try the following simple example out. echo "abc def ghi" | grep -Po " \K(.*?) " I was expecting to get a "def", but to my surprise ...
1
vote
3answers
50 views

How to express all files/directories at the extra -exec option of `find` command?

I have a task to copy all files from multiple directories with special names to a target directory. So I build this directory to test my command. The test directory tree looks like: . ├── dir1 │   ...
1
vote
2answers
36 views

Ack regex on filenames

According to this thread: Q: My understanding is that ack uses Perl-derivative regular expressions, is that correct? A: Yes. In fact, ack is written in Perl and just forwards the expressions ...
3
votes
3answers
167 views

Strip off word pattern at the end of string using sed

I have following string: ksh -x SCRIPT2.ksh $BUSSINESSDATE & PID=$!; ksh -x SCRIPT1.ksh $BUSSINESSDATE & PID=$!; I want to strip off the last word & PID=$!;. Desired result is: ksh -x ...
0
votes
0answers
29 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
16 views

Oracle / sql : calculation one or more value within the same field

I want select statement to sum the amount of value 352+652+20+356 that come in the same filed without need PL/SQL . [{Name:"account:account_1"&Value:352&New:256&CreditLimit:0} ...
5
votes
3answers
168 views

grep for multiple regexes, and count the number of occurences

Say, I have a file, and multiple regexes have to be searched in it and the number of matches for each regex has to be counted. Thus, I cannot combine the patterns: grep -Po ...
3
votes
4answers
161 views

pattern match and capturing in unix

I have a file like this: A1-1915435_1_MIMAT0000069_MirBase_miR-16_microRNA_1_22-A1-1915435_1_ENSG00000206737_ENST00000384010_U1_snRNA_73_115 ...
1
vote
2answers
76 views

Remove a line if regex exists only in 1st column of each line in a csv file

I have the following comma-delimited data (spaces used for visual clarity): 1 2014 23 2352 19.24 7.18 1 2014 23 2353 19.78 4.65 24 2014 23 2354 20.26 25.34 1 2014 23 2355 26.65 42.76 1 2014 23 ...
2
votes
4answers
82 views

how to find files based on filename range?

I have some files with numeric names: 2341a.po, 4567211someword.po, 0012.po, etc. I would like to find a set of files based on the numeric range. such as [126 - 363]. Normally I use regular ...
0
votes
2answers
44 views

2 consecutive digits using RegEx?

Is there a way to print words containing 2 consecutive digits divided with whitespace? Regardless of the input, is that possible? If yes, please share your ideas.
1
vote
1answer
336 views

Invalid back reference using grep

So I am trying to find 6-letter words that consist of one character repeated three times followed by another character repeated three times. For example aaabbb or oookkk. I am trying: grep -E ...
1
vote
0answers
19 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 ...
5
votes
3answers
158 views

Replace uppercase to lowercase except first letter of each word in specific line

I want to replace names that I received in uppercase letters only. The names are mixed with other information which should stay as it is. AUTH: at the beginning of the line identifies it as a line ...