3
votes
2answers
342 views

How to search a text file for strings between two tokens in Ubuntu terminal and save the output?

How can I search a text file for this pattern in Ubuntu terminal and save the output as a text file? I'm looking for everything between the string "abc" and the string "cde" in a long list of data. ...
0
votes
1answer
55 views

How to grep values under columns

How can I grep for a specific column name and display the value underneath that column. Sample data: StandByFile StandByPg StandByLSN StandByRcvBufUsed S0082160.LOG 621668 ...
0
votes
2answers
26 views

Multiple exclusion patterns with grep

I would like to select lines which do not match the specified pattern, where I have multiple patterns to exclude. As an example, I want to exclude lines which start with the keywords apple and banana: ...
0
votes
3answers
50 views

egrep for time in H:MM:SS format

Working on the file an need to grep the line with a time stamp in the H:MM:SS format. I tried the following egrep '[0-9]\:[0-9]\:[0-9]'. Didn't work for me. What am i doing wrong in regex?
0
votes
1answer
23 views

Restrict grepping to non-comment lines

I need to find in Perl source files lines containing bin/exim|SendEmail|Unformatted except of comment lines (lines starting with # with possible whitespace before). I know how to do it with a ...
1
vote
2answers
45 views

Find all php files which first or second line has more than N characters

I would like to find all php files on my server which first line or second line has more than N characters. I would like to print both the file name and the line content that was found. How would I ...
2
votes
2answers
90 views

How to grep a line with a backslash at the end of the line?

I'm trying to grep a line with a backslash at the end of the line like: abc\ def ghij ... I hope it can grep the line "abc\". I tried the command below but they didn't work. grep -EHn "\\$" ...
2
votes
2answers
40 views

Grep with ERE doesn't filter lines with -v option

I'm trying to use the extended regex option in grep to filter out from files, lines that have the following format of string at the beginning of the line. any-non-space-char: * I'd assumed ...
2
votes
2answers
394 views

regex : does not begin by “pattern”

I have a lot of lines in my LIST file and want to list only lines whose name does not start by (or contains) "git". So far I have : cat LIST | grep ^[^g] but I would like something like : #not ...
0
votes
0answers
22 views

TextWrangler 4.5.3 (3310)

I've got a huge batch of XML that has an element order problem, and instead of writing XSL to correct the import, I wonder if I can reorder the elements within TextWrangler? I need to select the ...
4
votes
1answer
77 views

Why does grep need a dot in a regex using '$'?

I though I knew grep, but maybe not. I want to find all lines in a file ending with ':' If I run grep :$ ~/greptester.txt but to my surprise, it gives no results. Sometimes I confuse '^' and ...
2
votes
3answers
131 views

What does really mean null string?

I'm sure most of us know that when we want that some regex matches with a string at the begin of the line we must use "^" ... But, I'm trying to understand what really means "empty string at the ...
0
votes
1answer
67 views

Search files for text matching format of a Unix directory

I am attempting to search through all the files in a directory for text matching the pattern of any arbitrary directory. The output of this I hope to use to make a list of all directories referenced ...
0
votes
1answer
159 views

Grep get everything except matching

Lets say I have a text file that says: Hello my name is agz. I am asking a question that is important. If i type: grep -v "is" /path/to/file, I should get no output because both lines have "is". ...
3
votes
3answers
69 views

Regular Expression: how to match 'ab','ac' and 'a'

Now, I have three strings to be matched by a single re -- 'a', 'ab','ac' I suppose one correct re should be 'a[bc]?', but it seems not correct. What is the correct one? I try it in grep command. And ...
-2
votes
1answer
63 views

Grep word in one file, and use that word to match in another file, adding the thing that follows the match

I want to grep several words in file1, and use each word to grep what follows after its match in file2. And then I want to add the string that followed the match to the word I used into file03, so ...
0
votes
2answers
43 views

How to grep a number following a keyword from a textfile?

How to grep the member id X01930 from the following file? Blah Blah ... Blah Blah Blah Blah ... Member ID: X01930 Blah Blah ... Blah ... Blah Blah ... Blah The string Member ID: is usually there, ...
0
votes
2answers
2k views

Why escaped single quote doesn't work in grep?

I am trying to match a string: * * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw with: crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n \'myApp\'.*$' ...
0
votes
1answer
50 views

Search files for regex and return which files contain matches

I searched everywhere but didn't find out how to return a file content that matches given words or a regex. cat /tmp/*.txt | grep "strings"
0
votes
4answers
277 views

Regular expression to find senders IP using grep or other languages

I have input file that contains: 19:04:01.631948 IP (tos 0xc0, ttl 1, id 0, offset 0, flags [none], proto UDP (17), length 48) 181.173.82.61.1985 > 250.66.33.195.1985: HSRPv0-hello 20: ...
1
vote
2answers
84 views

Finding folders only

My harddrive is in a mess, so I decided to do a cleanup. As a part of this, I want to merge all folders containing music into one. What I want to do is, look for any *.mp3's and *.aac's on my drive ...
2
votes
1answer
91 views

using grep -E with AND conditions (ex: (?=/fo)^(?=/mo))

I have little problem figuring out how to get a list of files that has: string "/fo" in it But does not have string "/mo" I'm trying to figure out that in folder with lot of text files... My ...
0
votes
1answer
132 views

Bash: Grep regular expression failing to work

When using grep like so: ps aux | grep 'processname' | awk '{print $2}' The PIDs of processes withprocessname is returned. When using this: ps aux | grep '^processname' | awk '{print $2}' I'm ...
1
vote
1answer
401 views

Extended regular expression new line

I seem to match two things using extended regular expressions: Newline. I have tried [ \n], [ \\n], both don't work Negative lookahead for string "timeout". I have tried (?!timeout) Can anyone ...
2
votes
2answers
432 views

Conditional spaces in a regular expression?

Using grep, how would I do this in one command line? I have this so far grep '\$[0-9][0-9]\.[0-9][0-9]' money.txt with various strings in the text file, but I'm having issues satisfying some of my ...
0
votes
6answers
637 views

grep *.c not working

I have a list of ".c" (c files) in the current directory. I have to find all the .c files in the current directory. The command that can be used id ls *.c But, another way is to use grep. so if i ...
1
vote
1answer
1k views

Specific case of non-greedy `grep`

I know there are many examples of a non-greedy regex with grep, but I'm having problems with my specific case. My file contains lines similar to: [X12345.Yabc.Z7989].[ALPHA/BRAVO].[CHARLIE.DELTA] ...
3
votes
1answer
2k views

Matching a number sequence in grep

So I'm trying to match a year number sequence with grep and this should be easy. I'm just a bit stumped that my simplistic regex isn't working. What I'm doing is running a tool which archives some ...
0
votes
1answer
104 views

How to get “grep -isrl”-like results for files in analogous subfolders?

I am working with a certain framework which has modules with consistent folder naming conventions. I would like to retrieve all files containing partial string foo from a high level directory, but I ...
3
votes
1answer
4k views

How to set line length limit when using grep (Filter result by line length)?

The use case is that I am searching for a particular CSS attribute in a directory of HTML/CSS/JS files (including sub-directories). Some one-liner JS libraries also have the CSS attribute that I'm ...
3
votes
3answers
163 views

unix command to verify span of word in text

What unix command(s) can I use to determine the line span that a word appears in text? The "span" being equal to the line number of the last instance of a word minus the line number of the first ...
0
votes
1answer
106 views

Show starting with a special line until a special line regex for Linux tail command

I use that notation at my log files: [something-something] somethings are necessary and variable length characters and numbers. My special log file includes line that has characters explained above. ...
-1
votes
2answers
99 views

Show matched lines for a given regex at Linux

I use that notation at my log files: [something-something] somethings are necessary and variable length characters and numbers. My special log file includes line that has characters explained above. ...
2
votes
1answer
79 views

sanity check file to produce binary answer

What Unix command(s) can I use to determine the existence of each of several words and the non-existence of each of several words which will produce a binary answer? For example: I want to be sure ...
6
votes
1answer
2k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
0
votes
2answers
406 views

grep doesn't produce the correct output when run on find command

My task was to print the number of files in the current directory without using ls and wc commands. I had typed the following lines in the script: #!/bin/bash find . -maxdepth 1 -type f \( ! -iname ...
1
vote
1answer
30 views

Looking for a command that will return the proc, func, etc that uses another proc, func, etc

Grep-ing for a function name to see where it's being used returns a list of rows and row numbers. Is there a smart way of using grep and awk to get the name of the calling procedure instead? Thanks
1
vote
2answers
201 views

Extract URLS from code statements in JS files

All, I want to extract all URLS mentioned in code statements in all js files in a folder. For e.g. if a js file contains this piece of code: var myURL="http://yahoo.com/signup" //var ...
0
votes
1answer
781 views

Why isn't this egrep invocation case sensitive?

I'm using the following egrep invocation as a filter for an ant build: egrep '\[.*\]|BUILD|time\:' The build.xml file has a huge number of empty or unimportant targets that I'm trying to filter ...
1
vote
1answer
411 views

Linux find and grep for files not match pattern

I'm trying to search the entire file system for specific text. This command does that but it gets hung up in certain directories like '/proc': find / -print0|xargs -0 grep whatever What I'd like ...
1
vote
2answers
452 views

Excluding paths in grep

I can't seem to find any documentation dealing with this: is there any way to stop grep from printing the path to the file of a matched line when searching over multiple files?
13
votes
2answers
8k views

Counting total number of matches with grep instead of just how many lines match

Does grep offer a way to count the total number of matches it makes? The -c option only returns the number of lines that matched the regex, but in this case I have multiple matches per line.
0
votes
2answers
255 views

Grep log for certain word only if followed by another word

I have a log file with entries like the following: Input php notice bob php notice winner php notice blah winner php notice asfsdf test php erro)r bob ...
1
vote
3answers
386 views

SW to replace a string in Windows

I have a text file (actually XML) that I want to be able to change using a command line. In other words, as part of a Windows batch, I want to locate a string (in this case @@@@, which uses a ...
2
votes
1answer
2k views

Using regular expressions in Linux with grep

I can't get this simple regular expression to work for matching emails: '\w*(?:\.\w*)*@\w*(?:\.\w*)*\w\{2,5\}' It should be working as I have tested it with regex pal and it works just fine. I ...
1
vote
1answer
615 views

Is there a command in Mac OS X that can perform multiline regex searching?

I want to do a simple regex search recursively through a directory that isn't restricted to single lines. I tried grep and ack, but neither seem to support this. I know it shouldn't be too ...
7
votes
1answer
168 views

Is there a `grep`-like utility to match strings instead of lines?

I'm using grep to extract lines that match a regular expression. How to get only the matches and not the whole line?
1
vote
2answers
1k views

match all strings containing only one '/' character

I have a very long file containing file paths, one on each line. I would like to retrieve a list of all directories listed which are only 1-level deep. As such, I would like to extract only those ...
2
votes
2answers
806 views

How to make «grep -P “foo (b.r)”» display only what's in the brackets? Do I need perl?

I have a large file, and I'm trying to get all matches of a regular expression from it. grep -P "foo (b.r)" Displays all the lines containing «foo b.r», and I'd like to display only what's inside of ...
0
votes
1answer
339 views

Which regular expression standard is used in grep?

Is the regular expression standard used in grep POSIX + ASCII or something else is mixed in?