Computing.Net > Forums > Unix > Awk : print certain column ranges

Awk : print certain column ranges

Reply to Message Icon

Original Message
Name: daelomin
Date: August 10, 2006 at 09:20:13 Pacific
Subject: Awk : print certain column ranges
OS: Linux
CPU/Ram: P4 1gig
Comment:

Hi,

How can one print columns say 4 to end with awk?

Thanks


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: August 10, 2006 at 15:08:55 Pacific
Reply: (edit)

Assume a default file delimited by whitespace; start at column 4 and print each column to the end. Print a CR at the end of each line:

#!/bin/ksh

awk ' {
for (i=4; i<=NF; i++)
printf("%s ", $i)
printf("\n") # CR at end of line
} ' mydatafile


Report Offensive Follow Up For Removal

Response Number 2
Name: daelomin
Date: August 21, 2006 at 02:59:09 Pacific
Reply: (edit)

Very nice! Thanks!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Awk : print certain column ranges

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge