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

learn more… | top users | synonyms (1)

4
votes
3answers
791 views

File manager which is able to filter using regular expressions

Is there any graphical file-manager which supports thumbnails for linux like thunar or nautilus, which allows me to filter a directory by a regular expression. For example typing /home/user/*tex ...
4
votes
1answer
441 views

Are there zero-width assertions in sed?

Is it possible to make lookahead or lookbehind zero-width assertions in sed? I want to emulate Perl's (?=) and family. My sed is not GNU sed version 4.0.
4
votes
2answers
54 views

sed regex issue

I'm trying to replace a string in a file: $RELEASE = '1234'; The whitespace between RELEASE and the = symbol could be either spaces OR tabs. The quotes around the version number could be either ...
4
votes
1answer
130 views

Using Regex in vim movment

Is there any way to use regular expression for movement in vim. For example, I want to move my cursor to the first occurrence of the pattern abc. So can I do something analogous to fa but now a ...
4
votes
1answer
767 views

Is there a tool in linux that allows multi-line regex expressions?

I'm wanting to find the results of a multi-line regular expression in linux. I tried grep, but like most linux utilities it's line based. Is there something similar that allows me to search across ...
4
votes
2answers
890 views

Parsing XML from a shell script

I have a datafile like this: <Key name="com.ahsay.afc.cpf.UserGroup" content="" allowMultiple="Y"> <Value name="rsv-id" inheritParentAttribute="Y" type="string" data="1328200856753" ...
3
votes
3answers
195 views

Multiline regex blank line delimiters,

I have a program which prints out data in blocks. Each block is delimited by blank lines. I would like to discard most blocks and only keep those blocks that contain something that matches a regex. ...
3
votes
3answers
4k views

extract part of string using sed

ls lib/oracle-11.2.0.3.0.txt | sed 's/lib.\([oracle.*]\)\.txt/\1/' It is giving the whole string instead of just oracle part until .txt What am I doing wrong? I can do it using awk as follows, but, ...
3
votes
3answers
258 views

Regex not matching

why this does not match..? sed -e '/--Updated?[[:space:]]+Date/d' inputfile this..: --Updated Date: 2013-11-06 15:32:13 d? is because sometimes I have Update Date, and sometimes Updated Date. ...
3
votes
3answers
2k views

Why can't find -regex match a newline?

Why does this fail? touch "$(printf "a\nb")"; find . -regex './.\n.' I also tried these, none of which work: find . -regextype posix-extended -regex '.\n.' find . -regextype posix-awk -regex ...
3
votes
4answers
2k views

How to insert the content of a file into another file (if regexp) in shell/perl

File1 Contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 Contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" ...
3
votes
3answers
494 views

How can I extract/parse a complete URL from a semi random string?

I'd like to have bash parse/extract a full URL (and only the url) from a random short string. Examples: bob, the address is http://www.google.com or https://foo.com/category/example.html is up ...
3
votes
3answers
102 views

History of Bash globbing

Is there a historical reason why Bash "globbing" and regular expressions are not identical? For example, I believe that in Bash [1-2]* matches anything that starts with a 1 or a 2 followed by anything ...
3
votes
3answers
1k views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> ...
3
votes
5answers
114 views

How to “grep” a string of a returned result

How to grep the number 50.0 from the string temp=50.0'C In JavaScript I can use the expression /temp=(.*?)'C/ to get it. But I cant get it running in grep.
3
votes
2answers
176 views

How to use restricted characters in egrep?

I'm trying to use a regex in egrep on Centos 5.10, based on the one I made from this question on SO. T12345 .{1,100}[\n\r].{1,100}2014.03.04 I can successfully match the regex to the content in my ...
3
votes
2answers
540 views

“grep: Unmatched [” error when using regex

I'm trying to find a pattern similar to this: tail -n 100000 gateway.log | grep -B10 -A10 'Nov 22 11:13:56 Received Packet from [10.50.98.68' Where "11:13:56" could be any time. This is what I ...
3
votes
5answers
585 views

changing pattern of a text file

A text file has contents something like chair table pen desk Now i want it to be changed and stored in a variable say var as below ('chair','chair'),('table','table'),('pen','pen'),('desk','desk') ...
3
votes
3answers
2k views

Awk: check for length of field

In awk. I am working on Solaris 10, so it's probably an old(er) version of awk. I came up with this rudimentary one-liner that works, at least for my particular input. awk -F\; '$3 ~ /[ ...
3
votes
1answer
7k views

Using regex inside if clause in bash

Look at this if block: #!/bin/bash str="m.m" if [[ "${str}" =~ "m\.m" ]]; then echo "matched" else echo "not matched" exit 1 fi exit 0 This should print "matched", but it doesn't. ...
3
votes
4answers
2k views

Applying a regex to stdin

In programing we often see the use of Regular Expressions. One of the most common forms is: newText = text.replace( /regex/, 'replacementString' ) If stdin is text and stdout is newText, what ...
3
votes
5answers
6k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
3
votes
5answers
214 views

Regex match in CLI

Is there something like a logical for the cli? I want to achieve this mv -t newfolder *.(png|jpg) so that alls jpg and png files are moved into newfolder. I know it could be done with mv -t ...
3
votes
3answers
814 views

Extracting text from a text file in bash

I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file. For ...
3
votes
3answers
180 views

sed - how to (not) match unmatched brackets

How can I do my operation only on lines that close their brackets? For example I want to change ".is" lines and add a bracket but not for lines with unclosed brackets. so these are changed ...
3
votes
4answers
282 views

Replace all occurences of \ except \N

I have a file like this: 1,2,subjects,\mat\hs,unix\,\Nato,\N,123,\N I want to replace all occurences of \ with #, except for \N, such that the output looks like this: ...
3
votes
2answers
265 views

Do procmail recipes have an alternator “or” operator?

Given the following procmail recipe: :0: * ^Subject:.*viagra.* * ^From:.*viagra.* /dev/null Procmail would only delete emails that were both from viagra, and had viagra in the subject. Is it ...
3
votes
2answers
95 views

What is the usage of pattern before substitute command in sed

There is an example in this link about sed: To delete the first number on all lines that start with a "#" use: sed '/^#/ s/[0-9][0-9]*//' What is the benefit of first pattern(/^#/)? It could be ...
3
votes
2answers
606 views

Find files starting with ~$ (MicroSoft Word Temp files)

For some reason my machine is full of M$ Word temporary files such as: ~$Filename.docx ~$AnotherFile.docx Can someone suggest a find/regex command to search $HOME and delete them?
3
votes
2answers
3k views

splitting textfiles according to a regular expression

By pasting into a text editor, I have a textfile gleaned from an online edition of Wilhelm's Yi Jing translation which I now want to split into 64 unequal parts, according to the 64 hexagrams of the ...
3
votes
2answers
7k views

sed one-liner to delete everything between a pair of brackets?

I am working with some text that is full of stuff between brackets [] that I don't want. Since I can delete the brackets myself, I don't need the one-liner to do that for me, but I do need a one-liner ...
3
votes
1answer
134 views

Why does grep treat '[D]ebug' string differently?

I've created simple text file named "T" to test the unusual behavior of grep: 1 Debug 2 debug 3 determined 4 Determined Tried different syntax: $ grep De T 1 Debug ...
3
votes
3answers
871 views

How can I grep for this or that (2 things) in a file?

I have a file that has "then"'s and "there"'s. I can $ grep "then " x.x x and then some x and then some x and then some x and then some and I can $ grep "there " x.x If there is no blob none ...
3
votes
4answers
599 views

Sort input file by the results of a regex

I'd like to sort a file based on the results of a regex expression. For example, if I have the following property declarations in Obj-C @property (nonatomic, strong) id <AlbumArtDelegate, ...
3
votes
2answers
1k views

simple command to strip header and footer from a file

I want a simple little command to strip an XML-Header and Footer from a file: <?xml version="1.0" encoding="UTF-8"?> <conxml> <MsgPain001> ...
3
votes
3answers
2k views

In a regular expression, which characters need escaping?

In general, which characters in a regular expression need escaping? For example, the following is not syntactically correct: echo '[]' | grep '[]' grep: Unmatched [ or [^ This, however, is ...
3
votes
2answers
1k views

What regular expression engine type does bash use?

I use RegEx Buddy to prototype and debug my regular expressions. RegEx Buddy allows me to choose between a number of different regular expression engine types (.NET, Java, Perl, GNU BRE, GNU ERE, ...
3
votes
2answers
548 views

ANDed conditional using regexp and variables

I want to test whether a line, read in from a file, has a specific beginning AND an ending containing a word held in a variable. Here's some code: The input file is: line one #; line two #; line ...
3
votes
1answer
167 views

Why doesn't this regex work?

I want to look at the output of git status -s to determine whether there are any untracked files in the tree. I tried the following test, but the regex doesn't match. Why not? $ git status -s ## ...
3
votes
1answer
78 views

find utility does not recognize bracket notation

I've two files in the current folder: submitWeb.m submit.m the following find does not show the two files: find . -regex .*submit\(Web\)?\.m But the above regex expression works fine in ...
3
votes
2answers
143 views

How to add a line in many files

I have many .html files and I need to add a meta tag after <head>'s start tag in each file. How I can do that? Can vim help me?
3
votes
2answers
2k views

Removing Color Codes From Output [duplicate]

Possible Duplicate: Removing control chars (including console codes / colours) from script output I'm working on a script to work alongside a program that I'm writing. What i'm trying to do ...
3
votes
1answer
6k views

grep and escaping a dollar sign

I want to know which files have the string $Id$. grep \$Id\$ my_dir/mylist_of_files returns 0 occurrences. I discovered that I have to use grep \$Id$ my_dir/mylist_of_files Then I see that the ...
3
votes
2answers
172 views

Why isn't this sed regex matching?

I've recently started learning sed. I did $seq 10 | sed '/[^049]/d' I was expecting 4 9 10 as output. But I got 4 9 Where am I making mistake in understanding this regex?
3
votes
2answers
2k views

sed or tr one-liner to delete all numeric digits

So, I have this textfile, and it consists of mostly alphanumeric characters. It's a standard document. But since I copied it and pasted it from a PDF, there are page numbers in there. I don't much ...
3
votes
2answers
41 views

Extracting just a single group from a regular expression

I am trying to get a list of numbers from some hacked-together log files using zgrep. So, I am using: zgrep -ie "total time: .* ms" * This returns the whole line that I care about. I'd just like ...
3
votes
1answer
1k views

Get all regex matches between two patterns and print them to file

I've got a file with a bunch of long lines. I'd like to grab every group between two patterns and print them to a new file, one match per line. I could manage to do this with Python, but I'd prefer ...
3
votes
3answers
190 views

What does . match?

In working with regular expressions, I have been told that a dot character . will match everything. Except for newlines \n. Are there any other exceptions? What about the NUL character \0, or the ...
3
votes
1answer
84 views

pcregrep newline lookbehind assertion bug?

Attempting to use pcregrep to print the first line after a blank line. For example, contents of file first line second line I need second line to be printed. Here are a few tests using the same ...
3
votes
1answer
60 views

Merging text files based on their filename

I have hundred of files with the following format: 2013_01_19_xyxyxyx.txt 2013_01_19_xyxyxyx.txt 2014_03_21_xyxyxyx.txt 2014_03_21_zxzxzxz.txt 2014_03_22_abababa.txt 2014_03_22_cbcbcbc.txt etc. I ...