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

Trouble with awk 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I got some trouble using awk under special circumstances.
I'm trying to fetch specific fields of a list.

Something like that:

Code:
> cat file.txt
0001 GE1 20100921 0x01 T1
0002 GE2 20100920 0x01 T2
0003 GE3 20090817 0x02 T3

So far no problem. If I want to get field 1 and 4 I simply use

Code:
cat file.txt | awk '{print $1 $4}' FS=' '

Where the output would look like this:

Code:
0001 0x01
0002 0x01
0003 0x02

Perfect! However in this specific case the file file.txt might look something like this:

Code:
> cat file.txt
0001 GE1 20100921 0x01 T1
0002 GE2          0x01 T2
0003 GE3 20090817 0x02 T3

See my problem ?
Using the above awk statement I get the following output:

Code:
0001 0x01
0002 T2
0003 0x02

Any idea how I could solve this issue ?

Regards,
Thomas
 
Code:
awk '{print $1,substr($0,194)}' file.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, sorry for the typo:
Code:
awk '{print $1,substr($0,19[!],[/!]4)}' file.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top