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!

Having troubles printing fields to output

Status
Not open for further replies.

jping45

Technical User
Aug 22, 2001
49
US
Hi,

I have output from a command and I want the output from one column printed out to one line, ex.
output from: <command> | awk '{print $3}'

123
456
789

I want it to be, with some formatting stuff:
123 456 789

Any suggestions???

Regards

Jake
 
Use printf, something like

awk '{printf $3 &quot; &quot;}'

Hope this helps.



CaKiwi
 
Hi Cakiwi,
here's the part of the script that I'm having the most trouble with:
for disk in $(lslv -l $phy | sed -e '/N/d' -e'/PV/d' -e'/\//d' | awk '{print $1}') ; do

lspv ${disk} | sed -n '/PPs/p' | awk '{ printf(&quot;%-20s%-20s\n&quot;, &quot;TOTAL PPs&quot;, &quot;FREE PPs\n&quot; $3 &quot;&quot;) }' >> ${LOGFILE}

Here's the output that I get:

TOTAL PPs FREE PPs
542
TOTAL PPs FREE PPs
18
TOTAL PPs FREE PPs


Here's what I'd like:

TOTAL PPs FREE PPs
542 18

Any suggestions...

Regards

Jake
 
If I understand correctly, this might do it.

BEGIN{print &quot;TOTAL PPs FREE PPs&quot;}
{printf $3; if (!(NR%2)) print &quot;&quot;}

If not, post some sample input to awk i.e. the output from lspv ..|sed .. |
CaKiwi
 
CaKiwi,
Here's the output from the command:
lspv hdisk0 | sed -n '/PPs/p' | sed -e'/USED/d'

TOTAL PPs: 542 (8672 megabytes)
FREE PPs: 274 (4384 megabytes)

Here's what I'd like it to be:

TOTAL PPs FREE PPs
542 274

Any suggestions??

Regards

Jake


 
I think substituting your awk program with this will do it.

BEGIN{print &quot;TOTAL PPs FREE PPs&quot;}
{printf(&quot;%-10s&quot;, $3); if (!(NR%2)) print &quot;&quot;}

or maybe

BEGIN{print &quot;TOTAL PPs FREE PPs&quot;}
{printf(&quot;%-10s&quot;, $3)}END{print &quot;&quot;}

Hope this helps. CaKiwi
 
Thanks again CaKiwi !! ;-)


Most helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top