Further understanding the Grep! lol


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Further understanding the Grep! lol
# 1  
Old 10-07-2013
Further understanding the Grep! lol

If I use the grep command for parsing files, does it stop parsing right after it finds the matching pattern or does it continue to parse that document?
Code:
grep -l "status" *.xml

# 2  
Old 10-07-2013
Hi,

Could you please give your exact requirement so that we can provide you a better solution/suggestion on same.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-07-2013
Of course its going to give list of all the files which matches the criteria in that particular directory...
This User Gave Thanks to selvankj For This Post:
# 4  
Old 10-07-2013
Quote:
Originally Posted by emc^24sho
If I use the grep command for parsing files, does it stop parsing right after it finds the matching pattern or does it continue to parse that document?
Code:
grep -l "status" *.xml

Most implementations of the awk utility will stop reading the current file when a match is found when the -l is given on the command line. (There is no requirement that grep quit reading the file when a match is found, but it is more efficient if it is done that way and most implementations of grep try to be efficient.) Note also that if the data being read is from standard input rather than from a path operand given on the command line, that might be treated differently.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-07-2013
Confirmed.
I tested a bunch of grep versions. They all stop reading the current file when invoked with -l and finding a match.
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 10-07-2013
From GNU grep manual:
Code:
-l, --files-with-matches
       Suppress normal output; instead print the name of each input file from which output would normally have been printed.  The 
scanning will stop on the first match.

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

understanding the purpose of <If env | grep -q $EXAMPLE>

I have seen this code in a few places and my understanding is they are using it to determine what app called the script. I have a script that is called by two different applications and what it to do one thing when called by one and something else when called by the other. How do I determine... (1 Reply)
Discussion started by: croyleje
1 Replies

2. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

3. Shell Programming and Scripting

help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here? find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies

4. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

5. Shell Programming and Scripting

This script cut size of files "Lol" change string in files

Basic: find . -type f -name “*.txt” -print | awk '{gsub("Ontem", "AntesdeOntem", $0); print > FILENAME}' *.txt The idea is in folder /home/myapontamentos I have some files and i need to change in all them the word "ontem" to "antesdeontem". But bigger files are cut (size i mean)... (4 Replies)
Discussion started by: single
4 Replies

6. Shell Programming and Scripting

my first script (lol)

hey peeps ive made my first script, its for my work made in HP-UX, kshell anyways the script copies 3 files from a spider system to the floppydrive of my collegeau, I want to check if there is a floppy in the drive otherwise the script just runs forever and I don't have that time a day... (1 Reply)
Discussion started by: EJ =)
1 Replies
Login or Register to Ask a Question