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

using tabs to align, $1 field too long 1

Status
Not open for further replies.

tagyourit

Technical User
Oct 20, 2008
22
US
Here's my output.

YZ_DISKPOOL 0.0 0.0
XYZ_123_789_DISKPOOL 44.0 43.6
UX_DISKPOOL 0.3 0.0
UNIX_DISKPOOL 0.0 0.0
UNIX2_DISKPOOL 0.0 0.0
UNIX3_DISKPOOL 0.5 0.0

I'm taking input which is comma delimited and feeding it to
| awk -F',' '{print $1,"\t\t"$4,"\t"$5}'

Because the first and second lines are different ( too short and too long ), tabs are doing what I hoped.

Is there a way to do this so the output lines up regardless of length of the first column? To a point of course. Let's assume that XYZ_123_789_DISKPOOL will be the longest in the first field and YZ_DISKPOOL will be the shortest.

Can I start my output for the 2nd column at a certain point so that it is aligned on the left, then a tab, then the 3rd column of data?

Trying to combine awk and printf to get my output, but I keep butchering it.
 
A starting point:
Code:
awk -F, '{printf "%-20s\t%s\t%s\n",$1,$2,$3}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is what I ended up using

| awk -F',' '{printf "%22s%10s%10s\n", $1,$4,$5}'

Thanks PHV!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top