Regular expressions are a means of matching a pattern of characters within a string.
1
vote
2answers
40 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 ...
0
votes
2answers
56 views
bash - reading user variable into bash script grep
I've tried every possible combination to get this bash script working. It's part of a larger script, and it basically prompts for a username (to check if it exists) and returns the appropriate ...
4
votes
3answers
78 views
Remove string from a particular field using awk/sed
I have a file (>80,000 lines) that looks likes this:
chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1
chr1 GTF2GFF gene 11874 14408 . + . ...
5
votes
3answers
170 views
difference between .* and * in regular Expression
I've a file named "test" that contains
linux
Unixlinux
Linuxunix
it's linux
l...x
now when i use grep '\<l.*x\>' , it matches :
linux
it's linux
l...x
but when i use grep '\<l*x\>' ...
1
vote
3answers
76 views
Trying to remove all ids from an HTML file with grep
I'm trying to remove all id=" "s from an .html file but I'm not sure where I am going wrong. I tried using regular expressions but all I am getting is the .html file rendering in my Ubuntu terminal.
...
1
vote
1answer
29 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 [email protected] (Example Dot Org):
where [email protected] is the sender's e-mail address and Example Dot Org is ...
0
votes
1answer
34 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
24 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
82 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
29 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
...
4
votes
3answers
107 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
42 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
!
...
3
votes
2answers
91 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
74 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
111 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
57 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
111 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
114 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
54 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
56 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
75 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 ...
1
vote
3answers
162 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
45 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
44 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 ...
3
votes
2answers
60 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
82 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
240 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
99 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
99 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
103 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
votes
1answer
45 views
Doing regex in python [closed]
I had a directory "/pcap_test" which contains several log files. Each file has a pattern like:
Pkt: 1 (358 bytes), LIFE: 1, App: itunes (INTO), State: TERMINATED, Stack: /ETH/IP/UDP/itunes, Error: ...
0
votes
2answers
96 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
157 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
157 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
133 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 ) ...
4
votes
2answers
149 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 ...
1
vote
3answers
207 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
156 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
222 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 ...
3
votes
4answers
503 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
117 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
194 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
235 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
319 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
129 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 ...
13
votes
3answers
433 views
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
Is there is any difference between these two.
[[ $a == z* ]]
and
[ $a == z* ]
Can I have an example where they would have different outputs?
Furthermore, how does the working of [[ ]] differs ...
2
votes
1answer
105 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
534 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 ...
2
votes
2answers
323 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 ...
9
votes
2answers
499 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 ...