Grepping from a point in a file to the end of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping from a point in a file to the end of the file
# 1  
Old 03-09-2011
Grepping from a point in a file to the end of the file

does any one know how to turn the equivalent of this command:

Code:
awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"

to

something that would use egrep instead of awk?

What the awk command does is, it searches the ops.log file for "2011 John Doe 8344". When it finds it, it will output all the lines (ALL), after that string to the screen.

doesn't even have to be egrep. anything but awk. Looks like awk takes too long if the file is huge.
# 2  
Old 03-09-2011
Have you looked at the -A option of grep?
# 3  
Old 03-09-2011
Or using quotes:

Code:
ant:/home/vbe $ more tst00001                     
     1  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     2  awk '/201 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     3  awk '/211 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     4  awk '/011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     5  awk '/11 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     6  awk '/2012 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     7  awk '/2013 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     8  awk '/2021 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     9  awk '/2011 John Dee 8344/,0' /tmp/ops.log | egrep -c "received request"
    10  awk '/2011 John Die 8344/,0' /tmp/ops.log | egrep -c "received request"
    11  awk '/2011 John Dae 8344/,0' /tmp/ops.log | egrep -c "received request"
    12  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
ant:/home/vbe $ grep "2011 John Doe 8344" tst00001
     1  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
    12  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"

(HPUX11.11...)

Last edited by vbe; 03-09-2011 at 10:56 AM.. Reason: added OSversion...
# 4  
Old 03-09-2011
Quote:
Originally Posted by joeyg
Have you looked at the -A option of grep?

i tried that.
its either i dont know how to use it properly, or its not working.

---------- Post updated at 10:25 AM ---------- Previous update was at 09:53 AM ----------

Quote:
Originally Posted by vbe
Or using quotes:

Code:
ant:/home/vbe $ more tst00001                     
     1  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     2  awk '/201 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     3  awk '/211 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     4  awk '/011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     5  awk '/11 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     6  awk '/2012 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     7  awk '/2013 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     8  awk '/2021 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
     9  awk '/2011 John Dee 8344/,0' /tmp/ops.log | egrep -c "received request"
    10  awk '/2011 John Die 8344/,0' /tmp/ops.log | egrep -c "received request"
    11  awk '/2011 John Dae 8344/,0' /tmp/ops.log | egrep -c "received request"
    12  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
ant:/home/vbe $ grep "2011 John Doe 8344" tst00001
     1  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"
    12  awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request"

(HPUX11.11...)


this will only output all lines matching john doe 8344. i want ALL lines that comes AFTER the specified string is found regardless of if the lines have the specified string on them or not.
# 5  
Old 03-09-2011
Can you post sample input and expected output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. Shell Programming and Scripting

Grepping one file column from another file

Hi all, I want to search the second col of a file as a sub-part of 4th col of another file and produce a joint output. In the example, search if B is contained as a sub-part in E:B:C (sub-parts separated by colons). Note the second row is not found doesnt find a match as F isnt there in col 4... (19 Replies)
Discussion started by: newbie83
19 Replies

3. Shell Programming and Scripting

Grepping text from one file in another file

Hello, I have a file with a large number of words each listed in sequential order one word per line. I want to search these words in another file which has the structure Both the files are large, but the words in the sourcefile are all available in the target file. I tried to grep... (2 Replies)
Discussion started by: gimley
2 Replies

4. Shell Programming and Scripting

Display file date after grepping a string in the file

Hi All, I need to recursively grep several folders for a MAC address and display the results with the date of the file name at the start. Even better would be if the final results were displayed chronologically so the newest file is always at the end. Oldest at the top, regardless of what... (8 Replies)
Discussion started by: quemalr
8 Replies

5. Shell Programming and Scripting

How to perform a hexdump using dd from start point to end point?

hi, I would like to ask or is it possible to dump a hex using dd from starting point to end point just like the "xxd -s 512 -l 512 <bin file>" I know the redirect hexdump -C but i can't figure it out the combination options of dd. Hope someone can share their knowledge.. Thanks in... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

deleting the part of the file(overwrite) using start and end point

here is the contents of bigfile.sql CREATE TABLE `Table11` ( `id` int(11) NOT NULL , `entityName` enum('Lines','EndUsers') COLLATE utf8_unicode_ci NOT NULL, `parentAllianceMigrationProjectId` varchar(255) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8... (30 Replies)
Discussion started by: vivek d r
30 Replies

7. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

8. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

9. Shell Programming and Scripting

Grepping a file based on input from a second file

how to grep a file based on another input file File1 ashu 1 ninetwo hari qwer 6 givefour jan fghj 8 noeight mar vbmi 7 noput feb -- --- File2 noput noeight --- -- Taking the input of grep as File2, a search need to be made in File1 giving File3 as output: (7 Replies)
Discussion started by: er_ashu
7 Replies

10. UNIX for Dummies Questions & Answers

How to change the file modification time of a file on nfs mount point

Hi I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file. So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)
Discussion started by: deepthi.s
6 Replies
Login or Register to Ask a Question