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

learn more… | top users | synonyms (1)

1
vote
2answers
40 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 ...
3
votes
6answers
353 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
28 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
0answers
25 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 ...
1
vote
1answer
21 views

Locate --regex with negative lookahead

Problem I tried to implement a negative lookahead when searching a file with locate like this: locate --regex "apple(?!t)" However I'm getting the following error, because there seems to be some ...
2
votes
4answers
262 views

Replace regex match with string containing match

I have a file with text as Afghanistan=+93 Albania=+355 Algeria=+213 American Samoa=+1 Andorra=+376 Angola=+244 It has all the country list and its dialing code. I want to replace: ...
2
votes
5answers
285 views

Duplicate lines and make them unique?

I have the following structure of text lines: 3923 001 L05 LV,L05 RM 3923 002 L12 RA,L12 LA 3923 003 I06 ALL 3923 004 G04 RV,Z09 ALL but i would need this: 3923 001 L05 LV 3923 001 ...
1
vote
2answers
82 views

how to replace a sed/perl expression (change and print only matched line) with a python expression?

I have asked this question to learn how perl could replace sed. Now I want to know how the following commands (which do the same thing) would look like for python: sed -n ...
1
vote
1answer
72 views

how to replace a sed expression (change and print only matched line) with a perl expression?

I am trying to move to perl (from sed). But how can I replace this sed expression with perl in a similarly short way? sed -n '/patternmatch/s%stuff%changed%p' file The only way I could do it was ...
0
votes
2answers
36 views

grep for lines/files that contain exactly X chars

Here's the output of a grep command I ran: [user@localhost] : ~/Documents/challenge $ grep -i -e ".\{32\}" fileA fileB fileA:W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDl fileB:observacion = new Observacion(); ...
0
votes
1answer
20 views

emacs dired regexp mark files beginning with

In Emacs Dired mode, I'd like to mark directories and files whose names begin with Addr but not files that contain Addr inside the name. I'm using RE-Builder to test my regular expressions and am ...
0
votes
2answers
28 views

Delete folders using regex

I would like to delete folders with specified regex, but I could not build a good regex. I have: /root /my-picture-2015 /my-picture-2015-1 /my-picture-2015-2 /my-picture-2015-1 ...
2
votes
5answers
137 views

Testing if files start with certain letters and contain no special character except for period at end next to file extension in a shell script

I have a shell script that runs a for loop to execute a command on multiple text files in a folder. I want to test if these files' names start with a specific set of letters (NA for instance), and ...
2
votes
1answer
42 views

How do I match the beginning of a line in a manpage?

When I do man zshbuiltins I typically want to search for a command. Suppose I'm looking for info on the alias command. I get a chunk of text like: : [ arg ... ] This command does ...
3
votes
3answers
122 views

Undo letterspacing with sed

I have a source text file containing text where some words are l e t t e r s p a c e d like the word "letterspaced" in this question (i.e., there is a space character between the letters of the word. ...
2
votes
1answer
34 views

Move up every other line to end of line containing character

I have ran 2 xpath queries piped together to retrieve certain information. However the results came out formatted on separate lines when I want them to be on the same line. So for example the lines ...
1
vote
1answer
34 views

regex usage in exim filtering

I'm trying to create an exim filter to block spam messages containing " 85% OFF" in the subject line. That's a blank space, then any two digits, then the percent sign, a blank space and the ...
1
vote
4answers
111 views

Delete everything before / on every line

I am trying to delete certain that appears before / on every line. I have something like: testing.db.com/7fad416d-f2b3-4259-b98d-2449957a3123 testing.db.com/8a8589bf-49e3-4cd7-af15-6753067355c6 ...
0
votes
1answer
25 views

Wrap all lines with character sequence in vim

So basically I copy/pasted some code, and I need to prepend and append some more code to each line. Each line is a function call, and is getting added to a switch statement as it's own case. Right ...
0
votes
0answers
13 views

How can I extract URLs from html content with ruby regexp? [migrated]

Lets go directly with an example since it is not easy to explain: <li id="l_f6a1ok3n4d4p" class="online"> <div class="link"> <a ...
0
votes
2answers
76 views

get values which only ocurre once in the vector

there is a vector of numbers I have which ascend (it is called t8_) 2 7 8 9 11 15 34 91 91 92 94 the problem is that some number happen two times - I don't want to remove them but they have to ...
4
votes
2answers
133 views

How to search for and replace text between two markers in bash script, with content from another file?

Say I had a block of text in the ~/.bashrc: #~/.bashrc # ...some commands... # aliases alias suicide='sudo rm -rf /' # end aliases # other commands I wish to replace that block of text with some ...
0
votes
1answer
64 views

Remove the exact same matching lines with sed

I have this bash script: sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie main/d' /etc/apt/sources.list sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie\-updates main/d' ...
0
votes
3answers
41 views

Shell pattern matching and arithmetic operators (+ - * / %)

This looks so simple but it isn't: [[ "1234+5678" =~ [0-9]+(\s*(\-|\*)\s*[0-9]+)* ]] && echo $? returns a 0. However, it actually should not do that, as only minus (-) and multiplication (*) ...
2
votes
1answer
74 views

Match a number range with grep

I need to find all processes that have in their names a number between 100 and 200 inclusive. I tried ps -ef | grep xclock -bw '[1-2][0-9][0-9]' but that includes 299. How to suppress it and ...
0
votes
2answers
57 views

Extract just the hostname and port number from tnsnames.ora file

I would like to give a hostname, and get a port number in return. My tnsnames.ora file looks like: DELUCA = (DESCRIPTION = (ADDRESS = (COMMUNITY = TCP.world)(PROTOCOL = TCP)(Host = ...
0
votes
1answer
27 views

Find directory names with N occurences of a set of characters

Sorry in advance, I know there are hundreds of posts about find, but I genuinely don't understand what's happening here and haven't been able to find a definitive answer to this question: how to match ...
0
votes
2answers
50 views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want ...
0
votes
3answers
45 views

match same lines

I've an file which I need to know if this file has entries which are the same The file contains entries like this: dn: cn=ccb2fa1a-6efb-4f29-b18b-72e226d76935,ou=Named,ou=Identities,ou=Active,o ...
0
votes
1answer
42 views

What does “\(\)” stand for in this command: grep(“-(mean|std)\(\)”, x[,2])

Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])
0
votes
2answers
59 views

Find all characters “[1-777])” at the beginning of the line

Pseudocommand perl -pe 'g/^[1-777])/g' data.txt where I try to all numbers at the beginning of a line with ")" following them etc 1), 67) and 777). Data where all question numbers should (etc 1), ...
1
vote
3answers
72 views

Match beginning of a line with something there?

I want to match the beginning of lines where the line contains something. Command in Perl/Sed 's/^.?/\section{}/g' but the problem here is that it replaces also the first character of sentences. ...
3
votes
1answer
115 views

Regex for crontab validation

I need to check in bash whether an entry into the crontab file is valid. Is there a crontab command switch? I can extract individual lines and try to control individual items through regex. But I ...
1
vote
4answers
327 views

How to use regex to match a pattern which does not have a specific string at the end

How to use a posix bre or a posix ere regex to match a word which does not have bak at the end. I want to do a ls | egrep '<regex>' to find all files which DO NOT have bak at the end of ...
1
vote
2answers
93 views

How to filter content between specific keywords using grep?

I got a bunch of files, and I want to find out the content between two tags st and et. if I use grep "st.*et" files, I will get these two tags involved in the result. Such as st Hello world! et. But I ...
1
vote
2answers
42 views

searching for the c++ in a string (regular expression)

I want to find if a string contains c++ in it (regular expression). what pattern should I use in grep function in R? This is my error: Error in grep(pattern = "c++", x = df[trow, "modeling"]) : ...
0
votes
1answer
36 views

How to integrate awk parameters in awk range pattern

I need to get something like this #Batch Job - AB1234 texts texts texts texts texts #-------- I used awk '/#Batch Job.*AB1234/,/#--.*/' filename and i went well. But then when I tried to ...
1
vote
2answers
62 views

UltraEdit - regular expressions replacement

I was trying many different combinations without success, at this point I would be really grateful for your help. I need to replace this end of the line multiple times (around 300) and it would be ...
2
votes
4answers
67 views

remove the content from the beginning to the first blank line

I'm trying to remove the content from the beginning of the text to the first blank line. --($:~)-- cat example.txt pedro pablo juan francisco emiliano martin So, I would delete: pedro pablo ...
5
votes
6answers
359 views

sed command to swap characters

My input file layout is: mm/dd/yyyy,hh:mm,other fields I need to format it as: yyyy-mm-dd hh:mm:00,other fields sample input: 01/02/1998,09:30,0.4571,0.4613,0.4529,0.4592,6042175 ...
0
votes
3answers
142 views

How to detect end of line with sed

I'm looking for a way to only execute replacement when the last character is a newline, using sed. For instance: lettersAtEndOfLine is replaced, but this is not: lettersWithCharacterAfter& ...
0
votes
5answers
157 views

How to grep an xml block in an xml file using a keyword in ksh

I have a file Sample.xml which contains a lot of services inside it and the structure looks like this Notes: I cannot use any XML parser tool as I don't have permission , read only My xmllint ...
0
votes
1answer
50 views

How to parse through a .dat file and get patterns such as timestamps and file size of a .jar file declared inside

I want to compare the size and timestamp of the following jar files in separate directories. First data is fetched by: grep -Eo ...
2
votes
1answer
30 views

Why does this command remove more packages than I want it to?

When I run the following command: # apt-get purge unity-scopes-m* I expect it to delete the following packages: unity-scope-manpages unity-scope-musicstores unity-scope-musique Instead, it wants ...
0
votes
1answer
30 views

postfix: what does /.+/ in pcre do?

I'm rewriting all sender addresses to one address in Ppostfix. main.cf includes this line: sender_canonical_maps = pcre:/etc/postfix/canonical_sender The file canonical_sender looks like this: ...
2
votes
2answers
48 views

Insert “return 0” between all braces in a file?

I'm setting up a fairly large (~50 functions) test library in C++. I forgot that the functions have to return integers. I actually forgot to put a return type at all, how dumb is that? I added the int ...
0
votes
0answers
34 views

awk search for string containing forward slash in variable [duplicate]

I'm searching for a string in a massive XML file. Snip: <sv:node sv:name="notfound"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> ...
0
votes
2answers
52 views

Search and replace with a regular expression in vi?

I would like to replace a string with regular expression that appears in multiple lines with the character "x": The problem is to replace words with the x in front that has an integer after the x, ...
4
votes
6answers
184 views

Append something to each list in a file

I have a file, lists.txt, that looks like this: // stuff at beginning of file var list1 = new Array(); i = 0; list1[i++] = 'a'; list1[i++] = 'b'; ... list1[i++] = 'z'; var list2 = new Array(); i = ...
1
vote
0answers
19 views

Interpreting regex wildcards with grep [duplicate]

This is a really simple question, but even after reading about wildcards/regex, I can't seem to grasp entirely what the differences between these commands are: grep . test.txt this one will look ...