Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Head and Tail problem

Status
Not open for further replies.

TysonG

MIS
Jun 10, 2002
13
CA
Hello all. I have what I believe to be a realatively easy problem, but I am having trouble fixing it.

I need to search through a text file for a string, then cut all text from the beginning of the file to that string. Head would do the job, but I don't know how many lines to cut. Basically, I need to do a search that returns only the line number that the search argument is on. This would allow me to use head. If that's not possible, I need a different way to cut the text file, like awk or sed, as to which I have no idea how to use.

Thanks much,
TysonG
 
hi

you can do

sed -n "/string to search/p" filename

e.g. search for my name is in text file fred.txt
and print it on screen

sed -n "/my name is/p" fred.txt
 
How about
Code:
awk "/pattern/{print;exit}{print}" file
CaKiwi
 
Thanks much all. These are all good replies. I used the grep -n <pattern> <file>|cut -f1 -d :|head -1 to get the line number of the pattern. Then it was just a simple head operation. Thanks a lot!

TysonG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top