Operating System - Linux
1828036 Members
1870 Online
109973 Solutions
New Discussion

Re: print each field in a row

 
SOLVED
Go to solution
lawrenzo
Trusted Contributor

print each field in a row

Hi,

I want to use awk to print the output of a command or file which is delimited with a space:

so

command


I would like to print





I appreciate the help.

Thanks

Chris.
hello
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: print each field in a row

Hi Chris:

# echo "f1 f2 f3 f4"|awk '{for (i=1;i<=NF;i++) {print $i}}'

...or, of course:

# awk '{for (i=1;i<=NF;i++) {print $i}}' file

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: print each field in a row

You can also use tr(1) to change blanks to newlines:
command | tr " " "\012"
Patrick Ware_1
Super Advisor

Re: print each field in a row

I want to do exactly the opposite. How can I take the following:

outputa
outputb
outputc


and turn it into this:

outputa outputb outputc


Dennis Handly
Acclaimed Contributor

Re: print each field in a row

>Patrick: I want to do exactly the opposite

Your thread is here:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1206784
Patrick Ware_1
Super Advisor

Re: print each field in a row

I actually made that thread AFTER the post above AFTER I realized that a new thread would be a better way.