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

How can I do the following......using awk

Status
Not open for further replies.

HIB049

Technical User
Jan 31, 2003
19
GB
Hello guys,

I am trying to split the following line using awk. I have tried every possible unix command sed, awk, cut, and tr, but to not avail.

PLS can you help.

What I am tryin to do is as follows

Line that needs to be processed is as follows:


root 1769 0.0 0.1 1568 76 tty1 S Jul09 0:00 /sbin/mingetty tty


I want to split the following above line to the following:

root,0.0,0.1,/sbin/mingetty tty


Can I achieve the above using AWK????????

I have used the following, but its not a perfect solution

YOUR HELP WILL BE APPRECIATED.

Ed
THKS.
 
How about this?
[tt]
awk -v OFS=, '{print $1,$3,$4,$11 " " $12}' infile[/tt]
 
Something like this ?
awk '
{printf "%s,%s,%s,",$1,$3,$4;for(i=12;i<=NF;++i)printf "%s ",$i;printf "\n"}
'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you everyone for your contribution to this request. I probably did not explain myself better, but what I am trying to do is as follows:

ps aux | grep hello

Output from hello:

root 1769 0.0 0.1 1568 76 tty1 S Jul09 /sbin/mingetty hello how are you my friend
root 1769 0.0 0.1 1568 76 tty1 S Jul09 0:00 /sbin/mingetty hello my friend I am fine what about you

I am trying to get the following information using awk

root,0.0,0.1,/sbin/mingetty hello how are you my friend
root,0.0,0.1,/sbin/mingetty hello my friend I am fine what about you

Notice, that the number of counts in the first line is different from the second i.e. "/sbin/mingetty hello how are you my friend" is $10 in the first line and "/sbin/mingetty hello my friend I am fine what about you" is $11.

Any help will be greatly appreciated.



 
And what about this ?
ps aux | awk '/hello/{
printf "%s,%s,%s,",$1,$3,$4
print substr($0,index($0,"/"))
}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
hello PIV,

What about when $10 and $11 variables haven't got a pattern to search for i.e.

root 1769 0.0 0.1 1568 76 tty1 S Jul09 /sbin/mingetty hello how are you my friend
root 1769 0.0 0.1 1568 76 tty1 S Jul09 0:00 /usr/local/bin a b c d e f g h

Any ideas????
 
If you don't care the hello pattern, get rid of /hello/

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

Part and Inventory Search

Sponsor

Back
Top