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

learn more… | top users | synonyms (1)

1
vote
2answers
536 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
233 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
363 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
467 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
2k 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
968 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
519 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
392 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
298 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
1answer
26 views

awk regex matches wrong?

Playing around with awk I noticed this behavior: [root@ror6ax3 ~]# grep open * | awk '$2 ~ /opens*/ {print $0}' install.log:Installing openldap-2.4.23-32.el6_4.1.x86_64 install.log:Installing ...
1
vote
5answers
47 views

grep for text that may or may not be present

Lets say I have a file batman; robin; superman; password = ""; wonderwoman green lantern if I want to check if there is a password present, i.e there is something entered in the "" . here is an ...
1
vote
3answers
20 views

To bold one line with Perl regex

I have 1. Lorem He he he % not sure spelling 2. Lorem ipsun I want to have \textbf{1. Lorem} He he he % not sure spelling \textbf{2. Lorem} ipsun My pseudocode attempt perl -000pe ...
1
vote
1answer
75 views

Need to remove lines till a pattern is matched

My C code needs to decode some application data that were received over a socket by another application. I used the Wireshark to export the packets(many) into a C array. But the array carries all ...
1
vote
4answers
102 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
53 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
207 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
112 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
83 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
610 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
3answers
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
143 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
153 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
43 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
123 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
131 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
89 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
127 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
164 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
56 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
944 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
419 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
345 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
54 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
262 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
1k 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
371 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
266 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
38 views

Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?

Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
1
vote
1answer
141 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
27 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
119 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
78 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
193 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
150 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
131 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 ...
1
vote
4answers
1k views

Change filename from lowercase to uppercase recursively

I have 1,000,000 files in some folders and subfolders. I want to rename them from lowercase to uppercase using shell commands. I don't want to modify the extension. only filename part. I have found ...
1
vote
1answer
39 views

Matching hexadecimals with gawk

I have a binary file with the following content (printed in hexadecimal): $ xxd -p virus.com 5669727573b440bb0100b90500ba0000cd21 I can match the first 5 letters (which are the alphanumeric string ...
1
vote
2answers
702 views

linux + match IP ADDRESS with 3 octets or with 4 octets

how to match IP address with 4 octets or with 3 octets in one command? target - match xxx.xxx.xxx or xxx.xxx.xxx.xxx ( syntax should fit for Linux and Solaris ) how to merge the following commands ...
1
vote
3answers
396 views

Recursively edit files based on parent directory's name

I'm facing an issue I'm not quite sure how to overcome. I have a large directory with hundreds of folders, all following the naming scheme "a_b_x", with x being a random word. In every one of these ...
1
vote
1answer
641 views

Regular expression how to get value in shell script?

I have to write a shell script to get value from a string, something like: string="abcdef" pathName How can I use grep command with the use of regular expression to get "pathName"?