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

learn more… | top users | synonyms (1)

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 ...
0
votes
1answer
79 views

(e)grep and atomic grouping [comprehension question]

I am trying to understand the correct use of »atomic grouping« a.k.a. »independent subexpressions« a.k.a. »non-backtracking subpattern« [this are the terms I found ...
0
votes
1answer
76 views

Comment the if statement and the matching endif keyword

In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify ...
0
votes
2answers
920 views

what is “an invisible whitespace character that takes up space”

One can look up Unicode Characters with Regular Expressions. On Jan Goyvaerts website I found a RegExp whose meaning I don't understand : \p{Zs} or \p{Space_Separator}: a whitespace character that ...
0
votes
1answer
534 views

How to highlight the whole log-line in color with multitail

I'm trying to use multitail to tail logs with color highlights. I defined a custom color scheme in multitail.conf, something like this: colorscheme:my-color cs_re:red:^\[E cs_re:yellow:^\[W ...
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> ...
0
votes
1answer
201 views

Regex awk to Cisco Interface

I would like to know if have some Sed/Grep or Awk regex to parse Cisco interface section, with specific attribute, like bellow. Content of file.txt ! interface FastEthernet0/1 no ip unreachables ! ...
4
votes
2answers
1k views

greedy and lazy regular expressions (comprehension question)

I am teaching myself regular expressions, and I got stuck at »greedy« vs. »lazy« repeatings. What I found out so far is that »greedy« means that the RegExp ...
4
votes
2answers
890 views

remove duplicate files

On my Mac OS X 10.6.7, iTunes duplicated every single file in my music library. Now I have 3,840 files instead of 1,920. The problem is that iTunes didn't simply duplicate the whole folder, but each ...
1
vote
3answers
463 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
1answer
921 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 ...
0
votes
3answers
2k views

Regular Expression for finding double characters in Bash

I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash). Main Question: Is there a simple way to look for sequences ...
1
vote
2answers
2k views

Regular expression problem(s) in Bash: [^negate] doesn't seem to work

When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. I tried the same thing with egrep, I tried to use it with double and single ...
1
vote
3answers
145 views

Check some property for every line of a file

I have several (427 to be precise) text files with a million lines each containing 31 numbers separated be spaces (possible double spaces). However there might be some data corruption and there may be ...
0
votes
3answers
99 views

regex suggestion

echo "223255/12345678 " | grep '[0-9a-zA-Z/\-\?:\(\)\.,"\+]{1,34}' According to the regex, it can have any of 0-9 a-z A-Z / - ? : ( ) . , " + of upto 34 chars in any order. Am I ...
1
vote
2answers
193 views

Regex and piped commands with sed

I'm finding really hard to use sed command, plus I can't seem to find well written tutorials. Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
2
votes
3answers
282 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 ...
1
vote
1answer
54 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 ...
0
votes
1answer
58 views

Help with understanding a regular expression

I have this regular expression \\..\\{3\\}$ I want to understand how this expression works to match a string. My thought is that it matches any 8 characters at the end of the line. Is that how this ...
4
votes
2answers
2k views

find command with regex {1,2}

I have been trying to create a find command string that will find all files that end with a number 1-99 but exclude all others. e.g. I want to find myfile1 myfile99 but not myfile456 and not ...
5
votes
2answers
723 views

exact match in regrex when using vim, man, or less

when using vim, man, or less, I want to do some exact match in regrex for example, when using man, I want to check the argument '-c' if I use /'-c' the matching could be -cim ...
-1
votes
3answers
6k views

How to tell grep to match special character at beginning of each word [duplicate]

I have certain questions regarding grep. Why does the following command match '<Hello'? $ grep -E "\<H" test Hello World <Hello H<ello What needs to be done to match '<Hello' only? ...
2
votes
2answers
214 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 ...
1
vote
2answers
411 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
3answers
387 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 ...
0
votes
2answers
138 views

regex, only the first occurence

I have a pipelined output from free -o -m | awk '{print $4}' I want take step by step two numbers the first and the second line. So i need two regexes. I tried with ^[0-9]{1,3}$ but this match all ...
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 ...
4
votes
2answers
275 views

Why does this add spaces? echo “x ax” | sed 's/x\s*/x /'

I want to find a x, and replace the 0 or more following spaces (\s*) with just a single space. echo "x ax" | sed 's/x\s*/x /' For some reason, instead of replacing the spaces with the single space, ...
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 ) ...
5
votes
2answers
908 views

Regexp in .ssh/config

At work, I often have to log into hosts which follow a common naming scheme, e.g. qc01 - qc12, hc01 - hc10, and so on. All of these need to get the same config values in my laptop's .ssh/config. Of ...
3
votes
5answers
3k views

Find files in multiple folder names

I am trying to list all the files from dir1, dir2, dir3 and dir4 which might be anywhere in as a sub directory of my cwd using the find command. I tried the following with no success: find . -type f ...
4
votes
1answer
584 views

Match word containing characters beyond a-zA-Z

To match a word one can use \v(\w+) From the vim help :h \w: \w word character: [0-9A-Za-z_] This works exactly as described in the manual. However, I want to match words that contain ...
-1
votes
2answers
2k views

Meaning of asterisk (*) in grep

[USERNAME@host ~] echo -e 'prdxxx\ndadxxx' | grep "da*xxx" prdxxx dadxxx [USERNAME@host ~] echo $SHELL /bin/bash [USERNAME@host ~] dpkg -l | grep -iw bash ii bash ...
4
votes
4answers
8k views

grep lines starting with “1” in Ubuntu

I try to search for lines that start with "1" using ls -1 | grep ^1* but it returns lines that do not start with 1. What I am missing here?
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?
2
votes
3answers
435 views

How to reverse-match a string in the Vim programming language?

I want to find the last index of any character in the [abc] set in the abcabc string but the search should start from the end of the string: " Returns the 0th index but I want the 5th. let ...
2
votes
2answers
996 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
2answers
799 views

Regex for phrase matching with case statement in ksh

I am trying to start or stop a service on AIX in ksh. I am trying to start to build in fool proofing for checking things like if the services is already down, etc. Here is my script #!/bin/ksh ...
1
vote
2answers
339 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 ...
2
votes
1answer
173 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?
1
vote
3answers
2k views

Print lines where first field has only four characters using regex in awk?

John Goldenrod:(916) 348-4278:250:100:175 Chet Main:(510) 548-5258:50:95:135 Tom Savage:(408) 926-3456:250:168:200 Elizabeth Stachelin:(916) 440-1763:175:75:300 output should contain the lines ...
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 ...
10
votes
2answers
4k views

How to run grep with multiple AND patterns?

I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence: grep pattern1 | grep pattern2 | ... So how to convert it to ...
2
votes
1answer
3k views

sed special character replace not working in shell script

I want to write a script 'test.sh' that will take a user's input and replace all special characters with a '\' + the character. My script: #!/bin/bash echo 'input='"$1" arg=`echo "$1" | sed ...
0
votes
1answer
424 views

Remove a block of lines between two patterns [duplicate]

Possible Duplicate: Show only text between 2 matching pattern In a bash script using sed how can I remove a block of lines beginning with -pattern a- and ending with -pattern b- where the ...
1
vote
1answer
751 views

Using grep command and backreferencing

This is a pretty basic question, but I can't get my head around it. I'm learning Linux and one of the questions i've been given is; *The word sentimentalment includes the same three characters ...
1
vote
3answers
682 views

find with user variables

I am trying to call find with a few variables. So far I had this: DIRECTORY="./ " FILENAME=-regex" .*test.*" find $DIRECTORY $FILENAME Which works fine. If I change the filename to : ...
1
vote
4answers
600 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] ...
2
votes
2answers
463 views

Parse apache logs to exclude IP ranges

I need to look for some requests in a huge pile of apache logs. My only requirement is this: I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
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 ...