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

learn more… | top users | synonyms (1)

0
votes
0answers
53 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
1answer
92 views

Match everything after backslash and before space

I have strings similar to the following: *unknown*\*unknown* (8) hello\morning (3) I'm trying to match just morning or *unknown\*. So far I have tried: [^\\]+$ But that matches from backslash ...
10
votes
5answers
1k views

How to print file content only if the first line matches a certain pattern?

I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this? How do I check for pattern? Is there a ...
-3
votes
1answer
122 views

Regular expression: when every alternate character is a digit

I am trying to write a Linux command using egrep that validates lines whose even character is a number. I am doing it this way: egrep "^(.[0-9])*$" text.txt However, this fails for i) empty ...
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 - ...
1
vote
2answers
100 views

how to swap text inside files [duplicate]

Inside my file I need to swap places of all instances of : grep 'search string' and sed '/string of text/,/string of text/{//!d}' In VI I have tried a regex with no luck - it says something ...
0
votes
1answer
18 views

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
-3
votes
1answer
43 views

Regexp pattern - is it correct and what is its purpose? [closed]

Is this pattern correct? logPattern = ^NAME.log(-\d+)?$ What is the purpose of this?
1
vote
1answer
163 views

Including or in grep pattern

I want to grep a word wrap in single quote or double quote eg. "myWord" 'myWord' I am using grep -rn "\"\|\'myWord\'\|\"" this should allow "myWord" , 'myWord" , "myWord' and 'myWord' , but ...
1
vote
1answer
98 views

Why is vi (but not cat) showing ^[[31m[^[[m^[[31m" after I use sed and output to a file I then edit? [closed]

When I use cat Variables/user-extensions.js | sed -e 's/css/XXX/' on an input file of the form storedVars["css_body"] = "css=body"; storedVars["css_main"] = "css=main"; I see output such as ...
1
vote
1answer
193 views

Sed replace portions of lines not beginning with http://

I'm getting stuck with sed.. I'm trying to prefix links in an html file with a / when they don't start with http.. I'm aware this is possibly not the best way to go about this but I'm just after a ...
1
vote
3answers
289 views

parse credentials from PHP configuration file

I'd like to write bash script to parse data from a configuration file. I searched for this but without finding something I could modify to suit my needs. Joomla! config file: public $access = '1';...
4
votes
3answers
576 views

sed, convert single backslash to double backslash

I have a json string, which has a potpourri of doubly escaped/singly escaped newline chars. Json parser doesn't allow its string value to have single backslash escapes. I need to uniformly make all ...
1
vote
1answer
79 views

grep -E regex syntax changed?

A lot of documentation I've read says that the following command should match lines where x appears at least 3 times in a row but no more than 4 times in a row: grep -E {x}\{3,4} E.g. http://www....
0
votes
1answer
539 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:*"...
4
votes
1answer
381 views

Match pattern \\\" using grep

I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the ...
0
votes
3answers
122 views

Pulling out a certain value from a string via regex

I've see a bunch of examples, but I just can't seem to make this work. Can grep output only specified groupings that match? for example seems like it should work, but I get either errors or no output ...
2
votes
1answer
117 views

Double square parenthese inside grep pattern

grep "^[[:space:]]*clientPort[^[:alpha:]]" zoo.cfg This is a grep pattern to extract the line that contains the port number from the configuration file. 1) Normally in a regex, I use square ...
0
votes
2answers
170 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 ...
1
vote
3answers
92 views

How to search multiple search patterns from a file with grep

If I search for multiple search strings in grep : usually just do: grep "search1\|search2" somefolder/*.txt but, what if I have 100 or more search strings? Can I say like this: grep "stringPattern....
0
votes
2answers
49 views

Bash script to copy specific directories with pattern matching

How can I copy directories from one location to another location that matches a pattern. For example: source = /media/src/ destination = /media/dest/ The pattern is as /b/w{2}_/w{2}/b. i.e all ...
2
votes
1answer
78 views

Sed: replace text keeping digit occurrence

I have some text like: Blablabla <b>[intlink id="</b>2204<b>" type="page"] Blalala I want replace it for remove the </b> and <b>, keeping the id="number". So it should ...
0
votes
1answer
98 views

Need to capture part of file name into variable

I have bunch of CSV files named like so in a directory: s_m_u_supplemental_fields_account_9_4_2015_11_26_Error.csv s_m_u_supplemental_fields_account_9_4_2015_12_3_Error.csv ...
1
vote
2answers
62 views

Remove last comma within a pattern

If I have the following text within a file (somefile.txt): CREATE TABLE "table_name" ( "id" int(11) unsigned NOT NULL, "some_field" varchar(10), ); CREATE TABLE "another_table" ( "id" int(...
1
vote
1answer
56 views

Remove word after match

Consider the following line of text (taken from a MySQL insert): "description" varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', I want to return "description" varchar(255) NOT NULL ...
2
votes
1answer
65 views

Meaning of this character class in perl?

I am new with PERL(though I have good background in reg-ex), I was going through one perl script and it has one characters class $alwayssep = "[\\?!()\";/\\|‘]"; Can anyone explain to me what is ...
2
votes
4answers
481 views

extract url between 2 strings in a file

I have a file in which each line is like this "372"^""^"2015-09-03 06:59:44.475"^"NEW"^"N/A"^""^0^"105592"^"https://example-url.com"^"example-domain < MEN'S ULTRA < UltraSeriesViewAll (18)"^"...
5
votes
2answers
365 views

How to change all strings in python file from snake_case to camelCase in sed

I've tried some sed patterns like this from commandlinefu sed -r "s/('[a-z]+)_([a-z])([a-z]+)/\1\U\2\L\3/" But somehow it's not working. For one thing they forgot the digits, which I can fix, but ...
6
votes
4answers
1k views

How to add a header and/or footer to a sed or awk stream?

I have a bunch of output going through sed and awk. How can I prefix the output with START and suffix the answer with END? For example, if I have All this code on all these lines and all these ...
1
vote
4answers
101 views

Match regular expression between delimiters

I have a file with several different lines. I'm looking for lines that contain(more or less) pattern like this: \[.*<.*>.*\] In other words, I want the lines that have <something> ...
0
votes
1answer
121 views

How to grep the following lines from a file?

I have a file which has the names of many files in a directory in the following format: A20150824.0950-0955_jambala_CcnActiveSessionCounterJob A20150824.0945-0950_jambala_CcnActiveSessionCounterJob ...
-1
votes
1answer
44 views

sed: regular expression,how to substitute?

I have those line on a text file 36) SIGCANCEL 37) SIGLOST 38) SIGXRES 39) SIGJVM1 40) SIGJVM2 41) SIGRTMIN 42) SIGRTMIN+1 43) SIGRTMIN+2 44) SIGRTMIN+3 45) SIGRTMAX-3 46) SIGRTMAX-2 47) SIGRTMAX-1 ...
1
vote
2answers
92 views

Awk & regular expression to process pgn chess games file

Below an extract of the sample.pgn file [Event "rated blitz match"] [Site "Internet Chess Server"] [Date "2015.08.20"] [Round "?"] [White "Villain"] [Black "Hero"] [Result "0-1"] [WhiteElo "1643"] [...
2
votes
1answer
103 views

How to combine POSIX character classes of a regex?

I need to combine different character classes in a regular expresion used by sed. I need to match [:word:] and the minus symbol -. How does that look like? All my attempts failed at trying or ...
1
vote
0answers
198 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
1answer
165 views

How to use sed to replace keys in a file using a regex?

I would like to modify a file to replace keys, suppose these keys are in the file as: 42NM 52NM 23NO XNNM I would like to replace anything with NM, with the word "Okay". 1 #!bin/bash/ 2 3 if [ ...
4
votes
1answer
306 views

POSIX behavior of sed's ^ and $ regex anchors with multiline pattern spaces

What is the POSIX behavior of the sed ^ and $ anchors when used at the beginning and end of a regex if the pattern space contains embedded newlines, like after you use the N command? Should they ...
0
votes
2answers
302 views

AWK, SED or GREP for extracting data from HTML file

Can anyone tell me which is best to use to extract the following data from a html file which was received with curl . <script>document.getElementById("test-summary").innerHTML = "<strong>...
5
votes
3answers
65 views

Censor text with regex

I'm currently running this command to censor an indented to-do list. sed -e 's/\(\s\+- \)\(.*\)/\1XXX/g' It's great except that I'd like the number of Xs to match the number of matched characters. ...
0
votes
2answers
635 views

What's wrong with this grep?

> output2.txt cd # some directory i'm trying to search find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do echo -n "${line%.js}" | tee -a ~/Documents/counter/...
1
vote
3answers
61 views

Remove words (letters followed by space) from a specific column

I have a file and the format is as follows: cat dog AHF123432 | 123432 | dhfshfjdh lion AFG23412 |23412 | dfshjhfjdhj I need to remove those words from first column which contains only alphabets i....
3
votes
1answer
87 views

What is the effect of the underscore in [A-Z] [_a-zA-Z0-9]*?

In regards to regular-expressions what is the effect of the underscore in [A-Z][_a-zA-Z0-9]*
1
vote
1answer
94 views

Bash script with “execute” command and strange regexp

So I was looking through Paul Irish's dotfiles and found reference to this bash script: #!/bin/bash cd "$(dirname "$BASH_SOURCE")" \ && source 'utils.sh' declare -a FILES_TO_SYMLINK=( ...
1
vote
1answer
40 views

How to express “There is a specified symbol in the following unknown numbers of characters” in regex(vim)?

I have many python code examples in my markdown files, which should be prepended with >>> symbols. So I write a vim function to do this job: function AddShellPrompt() range let lnum = a:...
2
votes
1answer
358 views

How to use regex inside exec with find?

Is it possible to use regular expressions based on the result (file name) inside the exec argument with find? I want to be able to "exec" based on parts of the argument, like: find . -name pattern -...
1
vote
1answer
59 views

grep also returning non matching lines

I'm trying to grep the output of strings and only find lines that start with a certain number of = chars. I tried strings data.txt | grep ^=* Sample output: 1~{, WX2 };K,< ========== ...
1
vote
2answers
377 views

Grep and ignoring leading whitespace

I've been working on a bash script to search for names of defines, and then grab the hex values for them and put them in the list. Once I have the list of names I'll attempt to search for "#define [...
4
votes
6answers
411 views

Grep the text which matches with a pattern

I was looking for a command which will print the selected portion of a line which matches the conditions. Eg, my text line is like this: p1=X||p2=Y||p3=X||p4=X||p5=X||p6=Y||p7=X I want to print ...
0
votes
1answer
63 views

sed - find string made of 4 numbers with a preceding character and append character

I'm trying to build a sed command that will allow me to search and replace some values in a large csv file. I have this column which contains years, like 2005 - 2006 2001 - 2003 and so on, but I also ...
1
vote
1answer
95 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-...