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!

grep

Status
Not open for further replies.

icu812

MIS
Sep 10, 2001
52
US
I'd like to be able to search the first colon delimited field in a file that has the following lines in it(file name is nfs.lis):
sp30:sp16:/stage:/stage
sp30:sp13:/mksysb:/mksysb1
sp16:sp13:/mksysb:/mksysb

For example: I want to grep sp16 nfs.lis and I want it to return just the sp16:sp13:/mksysb:/mksysb line. I do not want the sp30:sp16:/stage:/stage line to come up int the search. How can I accomplish this??????
 
how about grep sp16:s nfs.ls?
 
I was trying to complicate matters using the cut command when all I needed was what you suggested. Thank you. I truly appreciate your suggestion.
 
You can instruct the grep command to only look at the beginning of each line of the file by using the ^ (carat). Like this
grep "^sp16" nfs.lis

When you use special characters in a grep it is usually best to use the double quotes. If you want to look a the end of each line in a file use the dollar size (ie "search$" ).

Anything more complex, and I would suggest using awk. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top