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!

printing from field 2 to the end

Status
Not open for further replies.

erixire

Technical User
Jun 4, 2002
72
CA
Hi,

How can I tell to awk if I want to print from field number 2 to the end of the line (beside, each line has different number of field)?

So, if the line 1 has 4 fields, then I want to print field 2, 3 and 4. If the second line has 6 fields, I want to print field 2, 3, 4, 5 and 6.

Can somebody help me?
 
Hi erixire,

This will do it but it will leave the field separator
between F1 and F2:

awk '{$1="";print}' input > output

however, NAWK can take care of it with:

nawk 'BEGIN{FS=" "}{$1="";sub(" ","");print}' input > output

To use the nawk script, simply change the field separator
and the sub function parameter to match what your input file uses.

Hope this helps!


flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top