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!

field seperation problem in awk

Status
Not open for further replies.

balajipn

Programmer
Mar 30, 2004
65
IN
Hi,

I have a unix command "hogs" which gives the formatted output from the "ps -ef" command. The output of this command is given below.

============================================================
14768 5.2 02:54:09 236 root abmon -m 2
5246 0.3 00:40:06 160 root /usr/sbin/syncd 0
12646 0.1 00:13:38 2708 root /usr/sbin/sddsrv
6336 0.1 00:12:34 1260 root dtgreet
============================================================

I would like to extract each line into six fields. For ex, for the first record, following should be the values that I need.

$1 = 14768
$2 = 5.2
$3 = 02:54:09
$4 = 236
$5 = root
$6 = abmon -m 2

Can some one help me?. My $6 variable should contain everything after $6.

Thanks,
Balaji.
 
Hi

If the number on spaces between the sixth and following fields does not count, then you could concatenate them :
Code:
awk '{for(i=7;i<=NF;i++)$6=$6FS$i;NF=6}{ [green][i]your code here[/i][/green] }' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt], should work with [tt]nawk[/tt] too.

Feherke.
 
And what about substr($0,34) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top