query on grep command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers query on grep command
# 1  
Old 10-07-2004
Question query on grep command

Hai Friends

Can anyone provide me a grep command to print x to y lines in a file.

For example:
grep command to display 15th line to 21st

Thanks in advance
Collins
# 2  
Old 10-07-2004
Using grep, no. Maybe one of the others on the forum knows how.

Using awk, you can find a string and print out the lines between it and another string ( awk /"first string"/ /"second string"/ )

Using wc command, you can find the total number of lines in a file, then cat the file, pipe to tail, pipe to head - that combination can give you line 15-21.

Something like ...
cat hosts |tail -200|head -6
# 3  
Old 10-07-2004
I'd say sed is easiest.

Try
sed -n '5,10p' manylines

To print lines 5 thru 10 of the file "manylines"

Cheers
ZB
# 4  
Old 06-21-2006
grep question continued'

If I'm dealing with a huge file, and the lines I want spread in between the lines, how can I just pull those lines? I will print the lines to a file and use vi, but vi is not opening a huge file. For example, I have a file with 11163948 lines and the lines I want are between 10085200-10089210, 10090990-10091260 and 10604550-10604900.
# 5  
Old 06-21-2006
Use sed -n 'x,yp' where x is the starting line & y is the last line..

Just as explained in post above ur post..

Also to open a huge file you can use ISPF editor.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File grep quick query

Hi Experts, I need some suggestion on file grep. I am trying to find multiple pattern with the file grep as below grep "2013" trace.log | grep -f pattern.cfg -i > $LOG if ; then mail -s "Exception" "sample@abc.com" < $LOG fi Is it possible to obtain what pattern I got in the... (5 Replies)
Discussion started by: senthil.ak
5 Replies

2. UNIX for Dummies Questions & Answers

Query about 'rm' command

Hi, Can a file & folder be removed using single rm command. eg., rm <arguments> <file> <folder> Please let me know if this is possible. Thank you. (1 Reply)
Discussion started by: Vinay_Kumar
1 Replies

3. Shell Programming and Scripting

Grep query

Hi, What does this line do grep -E 'ORA-' $LIN_TOP/log/status.log > /dev/null 2>&1 Does this check in status.log and in std out, stderr also.? Thanks (3 Replies)
Discussion started by: nag_sathi
3 Replies

4. Shell Programming and Scripting

grep command query

list ALL file entries with a last modification date of September 20. using grep (1 Reply)
Discussion started by: polineni
1 Replies

5. UNIX for Dummies Questions & Answers

query related to grep

Hi All, The result for 'grep "cert_codes" /develop/sales/appl.srce/*.4gl' command will be saved at aa.txt grep "cert_codes" /develop/sales/appl.srce/*.4gl >aa.txt But I am not sure, whether, all result stored in .txt file in case of multi-line result. Please revert back if... (2 Replies)
Discussion started by: pbankar
2 Replies

6. Shell Programming and Scripting

grep/sed query

Hi all, I have one query,in my script,i give one input like sectionname that enclose with and that will search in specific file in specific directory.If found ,then it's search next section and begin of section ,sometext means different sectionname. p1 p2 p3 p4 p5 p6 I want to... (2 Replies)
Discussion started by: suryanarayan
2 Replies

7. UNIX Desktop Questions & Answers

ls grep query

Hi please can someone help me with a query? The following command is executed: $ ls abc def hij You execute the command: ls | grep f*. Which files will be displayed and why? thanks (13 Replies)
Discussion started by: tmn0004676
13 Replies

8. Shell Programming and Scripting

Grep query

As part of my never-ending nagios automation project I am need to implement the following run line into a loop; -bash-3.00$ grep ${feed} /usr/local/feed/service/clients/*/bin/* | awk -F/ '{print "To restart: /"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"$8"/"$9}' Which prints to screen; To restart:... (3 Replies)
Discussion started by: JayC89
3 Replies

9. Shell Programming and Scripting

grep command query

Hi I have file like this: Sun Jan 24 03:00:00 2010: *** Weekly Process - get_ens_files.pl START *** Sun Jan 24 03:00:00 2010: *** *** Sun Jan 24 03:00:00 2010: *************************************************** Sun Jan 24 03:00:11 2010: ... (2 Replies)
Discussion started by: koti_rama
2 Replies

10. Shell Programming and Scripting

Query regarding grep

In what cases the following command ignores lines in input file: $ grep -c "^" inputfile (1 Reply)
Discussion started by: amicon007
1 Replies
Login or Register to Ask a Question