grep

grep line below and above

Hi, I have to parse a very large file and I want to use the command grep (or any other tool). I have to check in a log line the word "FAILED", print the line above and below. For example: id : 15 Satus : SUCESS Message : no problem id : 15 Satus : FAILED Message : connection error And I need to print only id : 15 Satus : FAI...

Grep Usage help

I want to use grep to find all of the headers in a corpus, I want to find every thing up to the : and ignore every thing after that. Does anyone know how to do that? (Could I get a complete line of code) ...

What flavour of regular expression is grep?

I'm guessing it's not a Perl compatible regular expression, since there's a special kind of grep which is specifically PCRE. What's grep most similar to? Are there any special quirks of grep that I need to know about? (I'm used to Perl and the preg functions in PHP) ...

Default absolute path to grep in Linux kernel 2.6.18-128.1.10.el5

There was a recent change on the server I do most of my work on and all PHP exec()'s now need absolute paths. Its faster than asking IT to ask it here. So, does anyone know where grep is by default? ...

PowerShell search script that ignores binary files

I am really used to doing grep -iIr on the Unix shell but I haven't been able to get a PowerShell equivalent yet. Basically, the above command searches the target folders recursively and ignores binary files because of the "-I" option. This option is also equivalent to the --binary-files=without-match option, which says "treat binary f...

grep vs Perl. Should I mod this to work, or should I just replace it with Perl code?

I am writing something that will allow users to search through a log of theirs. Currently I have this, where $in{'SEARCH'} is the string they are searching. open(COMMAND, "grep \"$in{'SEARCH'}\" /home/$palace/palace/logs/$logfile | tail -n $NumLines |"); $f = <COMMAND>; if ($f) { print $Title; print "<div id=log>\n"; ...

Write a shell script that find-greps and outputs filename and content in 1 line

To see all the php files that contain "abc" I can use this simple script: find . -name "*php" -exec grep -l abc {} \; I can omit the -l and i get extracted some part of the content instead of the filenames as results: find . -name "*php" -exec grep abc {} \; What I would like now is a version that does both at the same time, but on...

Free alternative(s) to PowerGREP

First of all, great praise goes out to PowerGREP it's a great program. But it's not free. Some of it's options I'm looking for: Being able to use .NET regexp's (or similar) to find things in a filtered list of files through subdirectories. Replacing that stuff with other regexps. Being able to jump to that part of the file in some ...

Building grep strings dynamically

I am writing a shell script to do a "tail" on a growing log file. This script accepts parameters to search for, and incrementally greps the output on them. For example, if the script is invoked as follows: logs.sh string1 string2 it should translate to: tail -f logs.txt | grep string1 | grep string2 I am building the list of grep ...

Improving Shell Script Performance

This shell script is used to extract a line of data from $2 if it contains the pattern $line. $line is constructed using the regular expression [A-Z0-9.-]+@[A-Z0-9.-]+ (a simple email match), form the lines in file $1. #! /bin/sh clear for line in `cat "$1" | grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+"` do echo `cat "$2" | grep -m 1 ...

How do I grep server access logs for unique IPs and a specific page?

I want to grep my server logs to collect all of the unique IP Addresses, and also to see all of the requests for a specific page. What is the best way to do this? ...

Examples of getting it wrong first, on purpose

I just caught myself doing something I do a lot, and wanted to generalize it, express it, share it and see who else is following this general practice, to find some other example situations where it might be relevant. The general practice is getting something wrong first, on purpose, to establish that everything else is right before und...

How are regular expressions implemented in .NET? (C#)

I have just read this interesting article about the implementation details for various languages that support regular expressions. It describes an alternative implementation of regular expressions that uses non-deterministic finite automatons (NFAs) versus deterministic ones (DFAs). It claims that back-tracking DFA implementations (t...

To understand recursive grep in xargs

What is the practical difference between the following two commands? Command A find . -type f -print0 | xargs -0 grep -r masi Command B find . -type f -print0 | xargs -0 grep masi In short, what is the practical benefit of Command A? ...

To understand the practical use of Grep's option -H in different situations

This question is based on this answer. Why do you get the same output from the both commands? Command A $sudo grep muel * /tmp masi:muel Command B $sudo grep -H muel * /tmp masi:muel Rob's comment suggests me that ...

Grep (or maybe regex) check for pattern on lines before or after a match.

I have a simple grep command that returns lines that match from a file. Here's the problem: Sometimes, when a line matches, I want to include the line before it. What I want is a way to find all the lines that match a pattern, then use a different pattern to see if the line before each of those results match. Let's say I want to get ...

CURL Progress Bar: How to pipe and extract numbers only using grep?

This is what I have so far: [my1@graf home]$ curl -# -o f1.flv 'http://osr.com/f1.flv' | grep -o '*[0-9]*' ####################################################################### 100.0% I wish to use grep and only extract the percentage from that progress bar that CURL outputs. I think my regex is not correct and I am also not sure ...

total size of group of files selected with 'find'

For instance, I have a large filesystem that is filling up faster than I expected. So I look for what's being added: find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less And I find, well, lots of stuff. Thousands of files of six-seven types. I can single out a type and count them: find /rapidly_shrinking_drive/ -name "*offende...

retrieve MergeField values from mail-merged Word Document programmatically

I have a large collection of MSWord documents (approximately 40,000), which are the results of mailmerges (same main document, different data sources). One of the merge fields is a text field which could have the text "Yes" or "No". Is there an easy way to list which of the documents have that merge field set to the value "Yes"? (I'm...

changing chmod for files but not directories

I need to use chmod to change all files recursivly to 664. I would like to skip the folders. I was thinking of doing something like this ls -lR | grep ^-r | chmod 664 This doesn't work, I'm assuming because I can't pipe into chmod Anyone know of an easy way to do this? Thanks ...