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

learn more… | top users | synonyms (1)

2
votes
2answers
392 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
0
votes
3answers
22 views

Shell pattern matching vs. regular expressions occurence [duplicate]

I am relatively new to Unix, and I stumbled across one curiosity. Some shell constructs like case or find, employ pattern matching, but it is not quite regex. Other commands, like ed, sed, vi, and ...
0
votes
0answers
22 views

Loading csv data into hbase table in multiple columns using flume [on hold]

Is anyone know how to sink spool directory's .csv file data using flume to hbase i.e splitted columns into the hbase ? CSV File Format Data is: sample.csv ...
2
votes
3answers
57 views

Yum regular expression or wildcard search?

Fedora documentation says: 5.2. Advanced Searches If you do not know the name of the package, use the search or provides options. Alternatively, use wild cards or regular expressions with ...
14
votes
5answers
23k views

How can I use sed to replace a multi-line string?

I've noticed that, if I add \n to a patter for a substitute using sed, it does not match. Example: $ cat > alpha.txt This is a test Please do not be alarmed $ sed -i'.original' 's/a test\nPlease ...
2
votes
2answers
70 views

Find characters in the file

I need to find lines in the text file that have at least one x and at least two ys. I tried the following: grep -E "x.*y{2}" file.txt This method did not work. Is there another way to do it?
3
votes
2answers
265 views

rsyslog: make %syslogtag% equal length

I have rsyslog configured to log in the following format: $template long-iso,"%$NOW% %timereported:8:15% %syslogtag% %msg%\n" which produces logs like this one: 2013-12-14 15:59:39 ...
3
votes
6answers
8k 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> ...
2
votes
3answers
75 views

grep to find words with all vowels

Using grep -E and regular expressions I need to find words containing all of a group of characters in no particular order. For instance a word containing all vowels (aeiou) however the vowels can ...
1
vote
1answer
94 views

vim replace search text by manipulated search text

This is a very simplified version of my problem. Suppose I have a text file containing several places the code 20091a or 20092a or 20093a. I'm wishing to surround all this code by the text ...
5
votes
3answers
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, ...
0
votes
0answers
48 views

How to match this regular expression in bash? [closed]

I'm trying to match the sub string "~goddog" in the string "sort -u ~goddog/classes". I've defined two variables as below: cmd="sort -u ~goddog/classes" #eid="gogdog" eid="goddog" The following ...
12
votes
3answers
2k views

Why does [a-z] asterisk match numbers?

I have 3 directories at current path. $ls a_0db_data a_clean_0db_data a_clean_data $ls a_*_data a_0db_data: a_clean_0db_data: a_clean_data: $ls a_[a-z]*_data a_clean_0db_data: a_clean_data: I ...
3
votes
3answers
141 views

Replacing a pattern in line preceding another pattern of interest

I have a log file with many instances of statements as shown below: 14 Aug 19 16:30:11.506: <DATA> |POS|IDLE|1|01131844090|5950|$hostIp|$size |$data 20 Aug 19 16:30:12.439: <DATA> ...
26
votes
1answer
1k views

Why does my regular expression work in X but not in Y?

I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on ...
3
votes
3answers
118 views

Replacing string in all files found by grep. Can't get it to work

I'm trying to do what title says. So I find all needed files with grep: grep --include=\*.{php,ini,conf,sh} -ril -P "'([\d\w\-\_\.]+)(@domain.com)'" '/var/www_data/somepath/' Now I assume it's ...
3
votes
0answers
25 views

file(1) and magic(5) : prioritizing a result

My question follows that one: file(1) and magic(5) : describing other formats . I want to describe a FASTA sequence ( http://en.wikipedia.org/wiki/FASTA_format) It could be a DNA sequence (with only ...
3
votes
2answers
79 views

Extract specific set lines matching a rule

I have a large file with the logs as shown below. There are about 30000 instance of such events logged. I need to extract those lines beginning with RINGING and CLOSE (included) and which does NOT ...
4
votes
4answers
45 views

regexp which matches all tokens independent of order

I have a quick (and hopefully simple) question about regexps. I'm trying to think of a regexp which matches all of a set of tokens irrespective of order. So for example I have a file with the names ...
11
votes
3answers
3k views

Online grep exercises?

Are there any online grep tutorials that would feature some online tool for performing exercises? For example, having some predefined text sample and being told what patterns to find and so forth? It ...
20
votes
6answers
4k views

Regex for all 10 letter words, with unique letters

I am trying to write a regex that will display all words that are 10 characters long, and none of the letters are repeating. So far, I have got grep --colour -Eow '(\w{10})' Which is the very ...
-1
votes
2answers
39 views

How to remove a newline character in a particular line through perl?

I want to remove a newline character in a particular line through perl one-liner command. Input: 1407233497,1407233514,bar 1407233498,1407233515,foo mingstats&fmt=n 1407233499,1407233516,foobar ...
0
votes
1answer
32 views

How can I parse my String using regular expression to get only certain number of matches? [closed]

I am currently using this following regular expression to split my String into groups. ^([a-zA-Z0-9]*)(\[([a-zA-Z0-9=]*)\]){0,1}@([a-zA-Z0-9]*)$ Pty[R=4]@ID I am getting four groups 1) Pty 2) ...
2
votes
3answers
68 views

Find and change certain LaTeX coding in vim, using regular expressions?

How can I change the following LaTeX coding: \cite{1,3-7,9} to \cite{1,3,4,5,6,7,9} in vim? I would prefer to use regular expressions.
3
votes
1answer
48 views

Using sed to replace only the first two regex catches with different strings

So I'm trying to change two instances of a regex pattern to two different strings with sed like: sed -E "s/\\t([A-Za-z]|[-])+$/\\t`get_addr.py -1`/" /path/to/file.ext sed -E ...
8
votes
7answers
363 views

How can I “merge” patterns in a single line?

I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character? Now I am getting: pattern1 pattern2 ...
18
votes
4answers
12k views

How to diff files ignoring comments (lines starting with #)?

I've two configuration files, the original from the package manager and a customized one modified by myself. I've added some comments to describe behavior. How can I run diff on the configuration ...
2
votes
3answers
70 views

Checking if an input number is an integer

I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs ...
4
votes
5answers
103 views

Insert Lines after Multi-Line Regex Match

I've got an XML file I need to append to after a specific set of tags. Basically the file structure looks like this: <key>servers</key> <dict> ... Server Details ... </dict> ...
2
votes
1answer
887 views

lftp exclude syntax confusion

I am confused with the syntax description given for lftp from their website: -x RX, --exclude=RX exclude matching files -X GP, --exclude-glob=GP exclude matching files How ...
4
votes
3answers
189 views

Regex alternation/or operator (foo|bar) in GNU or BSD Sed

I cannot seem to make it work. GNU sed documentation says to escape the pipe, but that doesn't work, nor does using a straight pipe without the escape. Adding parens makes no difference. $ echo ...
4
votes
1answer
263 views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
6
votes
1answer
307 views

find words with all vowels in order from a file

I have a large dictionary file with 300,000+ words in it and I'm trying to find all words with the vowels aeiou in that order and have only exactly 5 vowels. My current attempt does not seem to be ...
3
votes
1answer
35 views

Problem with regular expression in gawk ('\<' not working)

I am trying to get into bash a little bit. I was going through this guide but the second example in this subsection on gawk doesn't seem to work. The problem is this command: ls -l | awk ...
14
votes
10answers
2k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTex, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
2
votes
3answers
50 views

bash: regular expressions in if expression

In my script on my ubuntu machine I declare a string like this: DEBUG_PACKAGE_LIST=$(apt-cache search dbg | awk '{ print $1 }' | grep -e "-dbg") For you to help you understand my problem here is ...
3
votes
1answer
44 views

Accept only y or yes with a one-line regular expression

I want to check if an input is y or yes (inputs in lowercase) and reject everything else What I have now is ^y[e]{'0,1'}[s]['0,1']$ But this accepts y, ye, ys, yes. I don't want ye and ys to be ...
2
votes
4answers
92 views

Matching string with a fixed number of characters using grep

I am trying to find all 6 letter words using grep. I currently have this: grep "^.\{6\}$" myfile.txt However, I am finding that I am also getting results such as: étuis, étude. I suspect it has ...
0
votes
2answers
35 views

add bracket across numbers at only end of each line

I have a file having lines as: ram_reg_10/raja_reg_9/raghu_reg_8 abc_reg_4/bcd_reg_5 cad/pqr_reg_91 I want to convert string "_reg_number" into [number] at only last of every line in vi ...
6
votes
2answers
176 views

Regex `/pattern/g` and ed `:g/pattern/`: which came first, and why `g`?

The g option (e.g. s/pattern/replacement/g) for many tools that use regex-style pattern matching and the :g command in ed, ex, vi, and vim have pretty similar usage and meaning: match the given regex ...
0
votes
3answers
39 views

Finding and replacing text inside awk block

I want to find and replace a value inside awk block. Here is a sample input file to my script P1 10,9:11/18013013582 ,10:1 ,167:0 ,487:5/E.164 11,9:15/310410532169026 ,10:60 ,167:0 ,487:4/IMSI ...
5
votes
3answers
235 views

How to remove dot and space from beginning of filenames

I'm trying to change jpg files named with a dot and a space at the beginning and with a missing dot before the end (like this . Startjpg to Start.jpg The dot makes the files hidden from sed and ls ...
2
votes
1answer
219 views

Aptitude regex engine

I was trying to lookup the versions of libdb in the debian archives with something like that: $ aptitude search '~S~ndev$(~nlibdb~(\d~|-~)!~v~rnative)' which didn't work as expected so I changed ...
3
votes
5answers
118 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.
4
votes
6answers
199 views

Finding the number of time a particular number in a file where range also specified

I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like, ...
2
votes
3answers
107 views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
4
votes
2answers
64 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 ...
1
vote
4answers
110 views

Simple sed replacement of tabs mysteriously failing

This ought to be really simple, but for some reason it is not working: sed -i.bak -E 's/\t/ /' file.txt Instead of replacing tab characters, it's replacing t characters. I've tried every ...
0
votes
3answers
109 views

Grep finding phone numbers in files

How would I look for files in the /etc directory (but not subdirectories) that contain a standard United States long distance phone number, written using the pattern of 1-###-###-####, where each # is ...
2
votes
3answers
119 views

bash - extract filenames from html file containing multiple links

I have downloaded an html file autogenerated by a script on a webpage. The file contains multiple links, including links to images I am trying to extract the full names of the images, for example ...