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

learn more… | top users | synonyms (1)

1
vote
1answer
50 views

Regular expressions help

what the different between these two regex expression ? AB\{4\} and (AB)\{4\} for the first expression I think that it repeat B 4 times, then for second expression it repeats AB 4 times. When I ...
1
vote
2answers
185 views

Match a simple Regex

I need to match this: (tt\d{1,10}) in a file with the file ending txt. I have tried grep and ack-grep but without results. ack-grep -G \.txt$ -g "(tt\d{1,10})"
1
vote
2answers
328 views

How to find and replace files contents that match a pattern?

Suppose we have a folder named Project. I would like find each file in the folder that contains the pattern &$ at the function call. For example should replace: AnyFunction(&$arg); with ...
1
vote
3answers
1k views

sed pattern matching

I recently asked someone at work about how to take the output of ipcs -qa and make it space delimited, so I can parse it/store it in the database for monitoring. He gave me this: ipcs -qa | sed 's/ [ ...
1
vote
2answers
386 views

pattern search and display the last occuring pattern?

I have a log file containing startup and shutdown times for everday. I want to see the last pattern pattern for startup and shutdown(which is located at the end of the file being updated everyday). ...
1
vote
4answers
1k views

Processing control characters

I have a log file which contains a bunch of non visible control characters such as hex \u0003. I would like to replace this using something like SED, but can't get the first part of the regex to ...
1
vote
1answer
44 views

Why isn't sed using the extended regex mode by default?

I am using sed. I was using a regex that was correct as far as I could see but sed did not do anything. Turns out that I was using \s+ which sed can not understand (?) and when I switched to [ ]+ it ...
1
vote
2answers
119 views

Find duplicate file names with specific matching pattern

I have a folder with some files (snippet of the contents of the folder) PAT1.URGRSVP.50.WR786842JOB11632.WRS20140.FILE0005.DAT PAT1.URGRSVP.50.WR786842JOB11643.WRS20140.FILE0003.DAT ...
1
vote
1answer
127 views

How to Replace Path in Search field using VIM

I'm trying to replace this text in VIM Actual Path /home/omipenguin/Servers\ Information/systemscript.sh/sysinfo.txt with this new path /home/sysinfo I tried %s/\/home\/omipenguin\/Servers\ ...
1
vote
1answer
43 views

How to match a literal '*' with sed?

I have this line in my file called test.php 'dbs_password' => 'a8b*cyP0', and want to replace into: 'dbs_password' => 'password-here', So I use this sed command with syntax: $ sed -e ...
1
vote
2answers
217 views

sed : Ignore line starting whitespace for match

I want to replace the default listening port of httpd to 9090. I can edit the line in httpd.conf file using below sed -i "/^Listen/c\Listen 9090" /etc/httpd/conf/httpd.conf But the line Listen 80 ...
1
vote
2answers
152 views

How can I combine grep with file and extra regex

I have a file of strings in each line. For example: AAAAA BBBBB CCCCC etc I want to check each string one by one whether it exists in a series of files in a specific directory. I ...
1
vote
4answers
223 views

using simple regex quantifier expression in grep

Does anyone know why ls | xargs -n 1 basename | grep -E '[0-9]{1}' does not only show occurrences of a single digit between 0-9? For example if I have: touch 1 touch 22 touch 333 touch test_file ...
1
vote
3answers
382 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
1
vote
2answers
1k views

Pattern matching from the input arguments

we're trying to enhance the scripts. Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...
1
vote
3answers
802 views

Compacting `find` name patterns

I am using find . -name '*.[cCHh][cC]' -exec grep -nHr "$1" {} ';' find . -name '*.[cCHh]' -exec grep -nHr "$1" {} ';' to search for a string in all files ending with .c, .C, .h, .H, .cc and .CC ...
1
vote
4answers
480 views

Stripping all vowels but the first from a set of strings

I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So: AbcdAEfd -> ...
1
vote
2answers
334 views

How do I generate a list of the characters occurring before a certain character only in lines that contain another certain character using regex?

I know that's super confusing (total noob-sorry!). To clarify, I have a text file that looks like this: 407-OL? 408-2-OL? 408-OL? 418-het? 420-1 and 2- OL? 429-2-left unscored? 430-2-left both ...
1
vote
2answers
275 views

Match neither regex

I have a Bash script which installs a customised JBoss. The name of the JBoss instance is checked against a regular expression to make sure that the name is valid: if [[ ! $1 =~ $instanceNameRegex ...
1
vote
4answers
66 views

regex matching with “locate”

I'm trying to use the locate command to find files in my home folder, however whenever I try and run this I get no results: locate -i -l 4 --regexp '^\/home\/jack\/[A-Za-z0-9\/\ ]*(My.)*$' I've ...
1
vote
2answers
40 views

How does “$” work in “apt-cache search something$”

I understand that $ apt-cache search package_name will search for matches in names and descriptions. But how does this work? $ apt-cache search package_name$ For example, $ apt-cache search ...
1
vote
3answers
80 views

How to get numbers by using regular expression, but only last one

In this example I can get 00. expr match "00 foo 99.jpg" '[^0-9]*\([0-9]\+\).*$' I want to know how to get last number from string, in this case 99 by using regular expression. The string may ...
1
vote
2answers
97 views

Backreferencing with sed

I have a database containing a list of unsigned longs representing a bunch of memory addresses followed by an offset within two brackets (e.g. Mem[offset], 0x2322AD4[3]), and some other data. What I ...
1
vote
1answer
73 views

What are the commands that you can use in the beginning of a sed command?

I initially learned to do sed search and replace like so: sed -e 's/<stuff>/<replacement>/' However I recently learned that these will do something different based on what command ...
1
vote
4answers
543 views

Replace text between brackets

I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like: SOMETHING [BAR, WIBBLE] SOMETHING [BAR] This gives the desired result of: SOMETHING [FOO, FOO] SOMETHING [FOO] ...
1
vote
4answers
2k views

Replacing XML entity values with positive lookaround

I'm trying to do some pretty simple sedding of a file: sed 's:(?<=<Type>)default(?=</Type>):super:' < myfile.xml The concept's pretty simple, using positive lookaround, find the ...
1
vote
1answer
32 views

grep: match pattern on a particular position

I need to match a pattern with grep, only if it starts at position 16. Lets suppose I want to match the string ' pattern' (starting with space) the following should match bla bla bla bla pattern ...
1
vote
1answer
63 views

awk date identification from input file

I currently have daily files that come in via FTP with incorrect dates in the first column of the file. I have figured out how to deduct one day to derive the correct date and print this to a new ...
1
vote
2answers
37 views

How can I append multiple extensions to a string with sed?

I want to create a script that will let me download images from entire subreddits at once, but I'm currently stuck on just getting the links right (one problem at a time! ^^). Anyway, since I can't ...
1
vote
2answers
67 views

Why is my grep + regex not working?

I recently decided that enough was enough -- I was going to learn to use grep fluently. It's been all of three hours and I'm already stumped by this toy problem. I'm currently syncing a RAID5 array, ...
1
vote
2answers
89 views

Ensure /etc/export contains rule using bash

What's a working example of modifying /etc/export using bash? Example: I want to ensure the following rule is present and valid: /export/home 2400:123::/32(rw,no_root_squash) And it should: Add ...
1
vote
3answers
78 views

a string representation using regex (modified)

I would like to use regular expression to represent a pattern with the following type of characteristics 1) It includes a continuous sequence of digit values. The length of this sequence it at least ...
1
vote
2answers
112 views

Remove 2 and 3 newlines in a text file but not 1

I'm developing on a max osx 10.8 and have no preferences to which tool to use probably sed but it doesn't matter. Update after comment: The input file uses windows new lines if that's complicates ...
1
vote
1answer
116 views

vim regex to search for lines containing string1 AND string2

How in vim/vi can I search for all lines that contain string1 and string2, where either string can appear anywhere on the line separated by whitespace and possibly other words? I would also like to ...
1
vote
2answers
55 views

Trimming one part if equal to another part?

I use an e-mail quote attribution string like this: On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org): where info@example.org is the sender's e-mail address and Example Dot Org is ...
1
vote
1answer
595 views

Confused about word boundary

I have been researching this a lot, but I am still not clear on it. What does word boundary mean? What does it do? So, for example, could someone explain this command to me please? egrep ...
1
vote
2answers
286 views

grep: invalid content of \{\}

Here's the command : grep '\(2\)[[:digit:]]\{\1\}' numbers What I want is to match exactly 2 digits after the digit '2', 3 digits if I change the digit '2' to '3' in my expression, 4 digits if ... ...
1
vote
2answers
287 views

How can I find matches with sed (or similar) for configuration parameters?

I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed. I have two shell scripts I'm working on and I'd ...
1
vote
1answer
53 views

cclive: what kind of regexes are allowed?

Is there a place where I can look, what kind of regexes I can use with the --tr option from cclive?
1
vote
2answers
237 views

How can I match this text in awk, printing line numbers for matches?

I have a text file thousands (roughly 148,000 lines long) that consists of a lot of sequences like this: b 29. b 52. c 84. c 83. c 94. c 93. c 61. b 38. c 81. c 92. c 28. c 37. c 27. ... and since ...
1
vote
1answer
983 views

reference problem in using sed

I'm trying to use sed command to find/replace a pattern in file. It gives: sed: -e expression #1, char 27: invalid reference \1 on `s' command's RHS My command is: sed ...
1
vote
1answer
328 views

Regex : all greek letters with 5 unique letters (meaning that each letter only appears once)

Another one I can't seem to solve : all greek letters with 5 unique letters (meaning that each letter only appears once). my solution : egrep '(.)([^/1])([^/1/2])([^/1/2/3])([^/1/2/3/4])' greek.txt ...
1
vote
1answer
207 views

How to match group 1 in a regex followed by a 0 rather than matching group 10

In regex plugin of gedit, I use a regex to match/search and another for substitution. In the matching regex, I only have one group. In the substitution regex, I use \1 to refer to the group, and I ...
1
vote
1answer
81 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
1
vote
1answer
23 views

Where can I find documentation on shell script syntax for using a regex within a variable construct?

I'm debugging a shell script (which I didn't write) that contains this loop: read line < "$pid_file" for p in $line ; do [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p" done ...
1
vote
1answer
84 views

Parsing csv with sed and perl one-liner?

I have a web server which stores configurations to PostgreSQL, and I plan to retrieve information from a certain table and then later parse it into csv format. PAYLOAD <?xml version="1.0" ...
1
vote
1answer
60 views

Help understanding an egrep expression

I stumbled across the following egrep expression: egrep '^([^aieou]*[aieou]){5,7}[^aieou]*$' /usr/share/dict/words on this page: http://matt.might.net/articles/sculpting-text The expression is ...
1
vote
1answer
117 views

Brace expression does not work in find regex

I have two folders, CA01 and CA02 under current folder, foo: foo -+ | +-CA01 | +-CA02 When I type find . -regex ".*CA[0-9]+" -exec echo {} + Or find . -regex ...
1
vote
1answer
113 views

Why is this line included in the `logcheck` report email?

In addition to the Debian provided rulesets, I have added a file /etc/logcheck/ignore.d.workstation/wpasupplicant.local (owner root:logcheck, mode 0644) to my newly installed logcheck setup. I have ...
1
vote
2answers
109 views

Tell a regex expression to skip the beginning of a line before matching

If I had a string like 45mb ./aaaa/bbbb/cccc/dddd and I use a regex like [^\/]*\/ it will match 45mb ./aaaa/bbbb/cccc/ I only want it to match ./aaaa/bbbb/cccc/ but I can't figure out how to do ...