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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I read first 5 characters of first line using AWK 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I have a big file and need to process it based on the first 5 letters of line one.

By knowing the 5 letters, I need to choose the appropriate processing command.

Example....

TIMES jlsadfsjl;kl;sdfjsdfsd sdfj;sdl;fksd
asjks sdjasl;fkasl; asfjal;sf asl;fkasd;lfa
asdas djfkfjsdk ,. sdafjsdfkjdjkfsdfj sdkds

I should be able to read and compare the "TIMES" to choose appropriate command to process the file.

Any sample code using awk will be useful.

Thanks in advance.

-Jay
 
Jay-

awk '{If(NR==1) five = substr($0,1,5)}{print five}' "inputfile"

flogrr
flogr@yahoo.com

 
Try this command:

awk "NR == 1 { print substr($0,1,5) }" inputfile

Jesus loves you!

Bye!
 
If you don't need to read entire file, use this example:

awk "NR == 1 { print substr($0,1,5); exit }" somefile

Statement exit causes the program to terminate.

God bless you!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top