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

learn more… | top users | synonyms (1)

3
votes
3answers
114 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
23 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
26 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
105 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
24 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
1answer
64 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
99 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
54 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
33 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
67 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
31 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
25 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
44 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
36 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
58 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), ...
3
votes
1answer
62 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
269 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
86 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
32 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
32 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
48 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
66 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 ...
4
votes
6answers
347 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
111 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
111 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
41 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
27 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
48 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
172 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 ...
1
vote
2answers
35 views

Regex for surrounding every word that contains & with $…$

I am thinking what is a robust approach for this. I try to match unsuccessfully by: [A-Za-z]*&[A-Za-z]* Which returns: so the mistake in \\&\hskip environment. How can you match ...
1
vote
2answers
58 views

How to do operation on individual matches in a full line

I have a Verilog line like this: if (i2_0&!(i2_1)) (posedge i0_0 => (o:1'b1))=(0, 0); How can I convert it to a line like: if (i2_0 == 1'b1 & i2_1 == 1'b0) (posedge i0_0 => (o:1'b1))=(0, 0); ...
1
vote
2answers
37 views

To Regex Pandoc Tables

Minimum Data to regex \documentclass{article} \begin{document} ------------------------------------------------------------- A B C D Header Aligned Aligned ...
1
vote
1answer
96 views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
2
votes
0answers
18 views

Why does find not match repeat / quantifier expressions with emacs regular expressions? [duplicate]

I have a file 'abcd' in my current dir. Using find -regex '\.\/[a-d]\{4\}' gets me no results. While the regex works fine in emacs itself. find, however, does find my file when I add -regextype ...
4
votes
3answers
238 views

RegExp testing with ash shell (BusyBox)

I need to do a RegExp pattern test on a certain bit of user input. This is the pattern I need to test the value against. ^([a-z]{2,3})\-([a-z][a-z]*[0-9]*)\-(\d+)$ An example match would be: ...
0
votes
2answers
54 views

How to match and replace an attribute value inside a tag

I am trying to replace the value of following node using sed command. <KeyValue key="EMPTY_SEARCH_CRITERIA" type="String" value="CS_CODE" comment="Configured empty search criteria."/> I am ...
0
votes
1answer
41 views

grep searching groups

I'm trying to learn to use grep groups, like sed \1\2\3, but have a problem. For example I filtering /etc/services file to separate all ports. What I do: ~$ grep -E '[0-9]{1,5}/(tcp|udp)' ...
0
votes
1answer
65 views

How to replace multiple occurrences of a pattern with sed

I use the following command to remove surrounding spaces between array keys that are strings or integers in PHP files: sed -ri "s/\[ ([0-9]+|(\x27|\x22).*(\x27|\x22)) \]/[\1]/g" file.php I thought I ...
6
votes
1answer
144 views

Why can't I escape the braces “]” in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
2
votes
2answers
50 views

Can't get GNU grep 2.12 to handle LF character in regex expression

I've been at it for over an hour, but can't find why it's not working. I'm searching an HTML document for "\nSome text". Simple enough. But he following commands won't work: grep -Po ...
0
votes
1answer
43 views

Use sed to only replace namespace in an element that has a parent element with a given attribute value

I want to replace the namespace in an xml file using sed (I've given up trying to do it from ant, where it is required). The main issue is that that there is a repeating list of elements - not all of ...
2
votes
1answer
20 views

Seeing all regex matches in a file in Bash

I'm in bash and I have a file, I want to find all matches of a regex in it and have them printed. How do I do that? Followup: Assume I want to print only unique matches, i.e. if a match appears ...
2
votes
2answers
97 views

How to escape correctly this word on vim?

I want to substitute this word ${ARRAY1[@]} with $1 on vim substitution command I did :%s:\$\{ARRAY1[\@]\}:\$1:g But give me error about number of repetition,i try also "" but doesn't work How to ...
2
votes
2answers
107 views

Extract substrings from each line. These substrings are in comma separated, “name=value” format

I have lines in a file that are comma separated. There are no column headers, it's mostly comma separated 'name=value' pairs. Here is some test data: ...