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

learn more… | top users | synonyms (1)

3
votes
1answer
1k views

Escaping of meta characters in basic/extended posix regex strings in grep

Is it possible to escape all meta characters of a string inside a variable before passing it to grep? I know similar question has been asked before on SE (here) and also a good explanation here, but I ...
3
votes
1answer
23 views

How do back-references match in sed?

I found a one-line sed command on this site which removes duplicate entries in $PATH. There is one concept that I can't get my mind around. It uses saved matches in the match section to detect the ...
3
votes
3answers
94 views

How can I get the first column of a 300GB txt file?

let me first explain my problem in detail. It's actually pretty simple. I have a huge .txt file, 300GB to be more preciese, and I would like to put all the distinct strings from the first column, that ...
3
votes
2answers
799 views

Wget - Mirroring a full website with requisites on differents hosts

I am trying to make a full static copy of a wordpress website with wget to be browsed without any network connection (all links and images must be converted). The different requisites for the pages ...
3
votes
1answer
276 views

Ex and Vi: buffers and regexes

I want to put regex matches to buffer but cannot get even simpler example y :.put myNewBuffer return msg [line] [put] [buffer] working ie how to put something to buffer? So to regular expressions ...
3
votes
0answers
131 views

How to use regrex with AWK for string replacement in this example? [duplicate]

Possible Duplicate: How to use regrex with AWK for string replacement in this example? Suppose there is some text from a file: (bookmarks ("Chapter 1 Introduction 1" "#1" ("1.1 Problem ...
2
votes
6answers
322 views

Regex that would grep numbers after specific string

So I have a line: ID: 54376 Can you help me make a regex that would only return numbers without "ID:"? NOTE: This string is in a file.
2
votes
3answers
986 views

sed one-liner to delete any line that begins with a digit

Pretend I am working with this file. The beginning of the first visible line is obscured, so ignore that. 43 is the beginning of the next line, and that line would be deleted. The next line (which ...
2
votes
3answers
700 views

sed, grep, or tr command that returns only Latin characters from a UTF-8 file

I am working with the text of the 300 tang poems, which unfortunately is a single file containing both Chinese and English. Since I am interested in 'extracting' the English, I hope to use sed, ...
2
votes
2answers
1k views

grep: regex only for match anything between parenthesis

How do I match word only between parenthesis Input : this is (test.com) Desire Output : test.com
2
votes
2answers
423 views

How to find files with a certain subpath?

I need to find all xml-files that are placed in folders named config. Also config must be somewhere under a folder named trunk. For example, I am interested in all files like below: ...
2
votes
3answers
95 views

Apply item replacement inside enumerate in Perl regex?

Data 7. Masi is the same as \begin{enumerate} A B ABC ha lorem \end{enumerate} 1. ABC is \begin{enumerate} P B Lorem maam \end{enumerate} which I want to be 7. Masi is the same as ...
2
votes
4answers
2k views

Extract IP address from a string

The Linux host command returns: hostA.domain.com has address xx.xxx.xxx.xx How do I get just the IP address and put it in the $ipaddr variable? open(FILE, "hostlist.txt") or die("Unable to open ...
2
votes
2answers
151 views

How can I extract the numbers in the file using sed or any other tool?

I have a file that has this format [ 2014/05/01 10:48:26 | 13963 | DEBUG ] It took 11.16837501525879 seconds to complete the process So I have thousands of lines like this and I would like ...
2
votes
2answers
135 views

SED change only start of line and preserve end of line

Basically I have a situation where I frequently need to modify my hosts file to access different servers at my workplace. In an attempt to automate the process. I've been trying to use sed to make the ...
2
votes
3answers
90 views

Pulling out keywords using standard command line utilities?

As an example, this is the pronunciation of "when" according to Wiktionary. enPR, IPA and X-SAMPA are different schemes for showing pronunciations. when:* {{a|US}} {{enPR|wĕn|hwĕn}}, ...
2
votes
3answers
506 views

Find word in sentence with Bourne Shell (sh)

I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example: #!/bin/bash INPUT='Lorem ipsum dolor sit amet.' if [[ "$INPUT" == *dolor* ]] then echo ...
2
votes
1answer
209 views

Regex doesn't work with grep

I have a string like this TEST="/dev/sda1 on /media/sda1 type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,quiet)" (Result from mount | grep sda1) ...
2
votes
2answers
54 views

Why don't I need to escape a character class in sed but I need to escape the rest?

I am confused with sed. I had a file with the following contents: [ 2014/02/10 14:45:15 | INFO ] Saving data for customer: 273667 [ 2014/02/10 14:45:15 | INFO ] Saving data for customer: ...
2
votes
2answers
123 views

Understanding -regex with GNU find

Background I have what I think should be a simple case. I want to find all files with "cisco" in the name and do something with those files (via xargs). Finding files with ls Before I use xargs, ...
2
votes
3answers
279 views

awk, sed, grep, perl… which to print out in this case?

I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
2
votes
2answers
349 views

Detect pattern repetition in a file

I want to make sure a file follows the following pattern: ... ... ... foo ... foo_KO ... ... ... bar ... ... ... ... bar_KO ... The file is extremely long, so, in other words, I want to make sure ...
2
votes
1answer
3k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
2
votes
1answer
57 views

sed regexp HEX char

i have this string: echo -e "a12\x8fb12\x9f"|xxd 0000000: 6131 328f 6231 329f 0a a12.b12.. i want delete this sequence string 12\x9f and 12\x8f with sed. i can do it with this ...
2
votes
3answers
68 views

Find a pattern with no repeated numbers in egrep

I need help finding a regular expression to match all digit sequences which has no repeated digit. Example: 198345 -> matched. 198315 -> not matched (1 repeated twice ) How can I achieve this in ...
2
votes
2answers
204 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
2
votes
2answers
979 views

extract last match from logfile till end

Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file? Example: grep -A222 ...
2
votes
3answers
770 views

with sed, how can I replace word within a matching line?

I am trying to write a sed expression to detect lines similer to this: s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux and replace the "ttys0" with "something_else" I do not want to detect ...
2
votes
2answers
3k views

Sed: replacing digits

I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d: /var/log/ufw.log { rotate 7 weekly missingok notifempty compress delaycompress ...
2
votes
1answer
174 views

sed one-liner to delete word-medial spaces

I have a text file that consists of some N ORMAL E NGLISH W ORDS in all-caps. Unfortunately, these words all have a space between the first and following letters, which is not acceptable. I tried ...
2
votes
3answers
703 views

Filtering paths to a specific depth

I'm using rsync and the flags -nPaAXz ~/ to check which files are going to be copied. This is far too verbose to make any sense of. How could I filter the output so I view the list of files/folders ...
2
votes
2answers
26 views

can regex capture groups be used in GNU find command?

With the GNU find command (GNU findutils 4.4.2), a regular expression can be used to search for files. For example: $ find pool -regextype posix-extended -regex ...
2
votes
3answers
79 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.
2
votes
2answers
66 views

Condition string matches reg.expression

So, in my script, I have to decide whether one of the parameters is a valid email address. I was trying, but it failed. if $maddr="^.$*\(@\)\(*\)\(.\)\(??*\)" then ... It's meant to mean: at least ...
2
votes
1answer
88 views

How to print strings matching a pattern with grep?

I want to get a list of strings matching the following pattern: CLASS_NAME:"*" where * represents any number of characters. I tried: grep -o CLASS_NAME:\".*\" script.js and grep -o ...
2
votes
1answer
115 views

Counting consecutive repetitions of a specific character (e.g. ,)

Say I have a file with lines like the two following: foo,bar,,baz,xy foo,,bar,baz,xy,, I would like to count how many times I have ,, (two consecutive commas surrounded by any other character) in ...
2
votes
2answers
89 views

Trouble getting regex to work with find

I'm having a lot of trouble getting find to work with regex flags. Im using egrep on its own to find a date pattern in a file, like this: egrep '[0-9]{4}-[0-9]{2}-[0-9]{2}' which will return dates ...
2
votes
2answers
131 views

regular expressions with grep

I have this command right here: grep -B10 -A10 '14:14:50 {"channels":["/alerts/6979/new"],"data":"New alerts for unit 6979"}' mygateway.log Rather than searching for 14:14:50 I would like the 50 to ...
2
votes
1answer
172 views

grep all words with specified length, without letter x

So I am stuck here: grep -E '^....c...c...$' shows all words with the expr I need. Now from this words I only need the ones that don't have a x. Who can help me?
2
votes
3answers
2k views

remove white space before delimiter with sed

I have data of the following format that I want to input into LibreOffice calc data | num | num | num | num For some reason Libreoffice does not think the string "3214 " is a number by ...
2
votes
2answers
352 views

AWK match string, not Regex

How do I match a string with AWK? Say I have the string [(*.+ it should only match strings containing the string [(*.+. The string is entered by the user, so if you know a cli utility that can ...
2
votes
1answer
244 views

Delete repeated words between brackets inline

Our input looks something like 2012-04-17 [GBPGBP] 2012-04-13 [GBP GBP] 2012-04-13 [GBP] 2012-04-11 [GBPGBP] 2012-04-11 [GBP GBP] 2012-04-10 [GBPGBP] 2012-04-06 [GBP GBP GBP] 2012-04-17 ...
2
votes
2answers
5k views

Find all lines in a file with a certain character at a certain position

I have a lab question asking me to use grep with a regex pattern to match every word where the third letter from the beginning of the line is an "a" and save it with a redirect. How can I do that?
2
votes
3answers
131 views

expr help - managing strings

I need to take text like this: A234321=http://www.google..... a normal URL And pull out only the URL, getting rid of the first part. I think I can use expr to do it, but I can't figure out the ...
2
votes
2answers
1k views

Regex : match 2nd and 3rd character

I was doing some exercises on regular expressions, but I can't seem to be able to crack this one : egrep in a file where the 2nd and 3rd character are the same. I tried : egrep '^..{2}' ...
2
votes
1answer
119 views

Awk regular expression syntax with number of repetition - different handling between gawk 3 and gawk 4

I am having trouble understanding or explaining why the following expression fails in gawk 3.1.x and yet works in gawk 4.1.x: (Minimum working example) echo ";#ADCDE#" | awk '/#.{5}#$/' -> produces ...
2
votes
1answer
92 views

Search for “not newline” in vim?

To search for A T\n in vim I can just do /A T\n What would be the equivalent for not newline at the end? /A T[^\n] did not work.
2
votes
2answers
163 views

Print some fields of /etc/passwd

I have a question concerning the usage of wild cards in Linux. Here I have some lines from a long list of lines in the /etc/passwd -file. root:x:0:0:root:/root:/bin/bash ...
2
votes
3answers
145 views

mv files to a different path which is constructed via a regex replacement

I have a directory full of files stored in subdirectories according to their filename, i.e.: 20d1/d325/52d1/20d1d32552d1a95249e62662fbdf924dd72c4027.jpg ...
2
votes
1answer
1k views

Forcing Bash to use Perl RegEx Engine

As you may already know, a lot of the features modern RegEx engines support (back referencing, lookaround assertions, etc.) are not supported by Bash RegEx engine. Following is a simple Bash script I ...