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

unconstant NF, want fields 1 to (NF-1) printed on same line.

Status
Not open for further replies.

will27

Technical User
Jun 13, 2007
23
US
Dear all
I am sure this is a simple quesiton for most people visiting this forum.
the question in detail is as following:
A data file with unconstant NF, the fields I want to reserve is field 1 to field (NF-1), they should be printed out on the same row. for example

thank you for your kind help # 6 fields
# will be printed out like
thank you for your kind # 5 fields

Regards
will

 
Hi

You mean to cut off the last field ?
Code:
awk '{NF--}1' /input/file
Code:
awk 'NF{NF--}1' /input/file
Code:
awk '{$NF=FS;sub("["FS"]+$","");print}' /input/file

[gray]# or[/gray]

awk '{for(i=1;i<NF;i++)printf"%s%s",$i,(i<NF-1?FS:RS)}' /input/file

Feherke.
 
Thank you,Feherke
I really appreciate your quic but big help .

will

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top