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!

awk spacing help...

Status
Not open for further replies.

chanman525

IS-IT--Management
Oct 7, 2003
169
US
Hey all, I've got a file that I'm trying to clean up and look organized. The first column seems to be throwing everything off. Here is a copy of the printf function and how I am using it...

awk 'BEGIN { print "Equip DATE TIME LAST FIRST S990"
print "----- ---- ---- ---- ----------"}
{print $1" "$3" "$4" "$5" "$6" "$7}' /dcos/eis/log/busted2


and the output is the following...

Equip DATE TIME LAST FIRST S990
----- ---- ---- ---- ----------
LRT243 03/06/07 06:31 Yantis, Gene:S990GY1 334
LRT170 03/06/07 06:38 Gutierrez, Ranae:S990RG5 331
OTHPLM185 03/06/07 06:39 Garvey, Brian:S990BG4 335
OTHPLM184 03/06/07 06:43 Garvey, Brian:S990BG4 335
OTHPLM182 03/06/07 06:45 Byers, Charles:S990CB9 335
SPEC851 03/06/07 06:46 Byers, Charles:S990CB9 335
OTHPLM186 03/06/07 06:49 Martino, Ryan:S990RM6 335
SPEC848 03/06/07 06:49 Martino, Ryan:S990RM6 335
SPEC854 03/06/07 06:54 Martino, Ryan:S990RM6 335


If you can tell, when the first column is 3 characters longer on some lines, it throws the rest of the line off to the right. How do you get these to space out evenly?
 
You said you were using printf, but the example uses print.

With printf, you specify a format string. This is how you can straighten your output up.

Code:
printf("%-10s\t%s\t%s\t%s\t%s\t%s\n",$1,$3,$4,$5,$6,$7)

This will print your first string left-justified in a 10 character field, then tab separate the rest. One thing to always remember with printf is that you have to provide your own newline (\n).


- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
Sorry about the confusion on the printf. I had it in my head when I was typing. Anyway, I'm not getting a syntax Error ( not expected when I entered that into my script. Here is the code exactly how I put it in:

printf ("%-10s\t%s\t%s\t%s\t%s\t%s\n",$1,$3,$4,$5,$6,$7) /dcos/eis/log/busted2


is this correct?

Sorry if this seems mundane to you, I'm pretty green at AIX scripting. Just trying to pick it up.
 
Please post the entire script so we can see that in context.

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
#!/bin/ksh
date1=`date +%D`
egrep '0(6:(3[1-9]|[45][0-9])|7:)' history.log >busted
egrep "Out" busted > busted1
egrep "$date1" busted1 > busted2

#mail -s"After 6:30 Equipment Checkout" Jason.M.Alge@lowes.com < /dcos/eis/log/busted2

#mail -s"After 6:30 Equipment Checkout" Anthony.E.Adams@lowes.com < /dcos/eis/log/busted2

#awk 'BEGIN { print "Equip DATE TIME LAST FIRST S990"
# print "----- ---- ---- ---- ----------"}
#{print $1" "$3" "$4" "$5" "$6" "$7}' /dcos/eis/log/busted2


printf ("%-10s\t%s\t%s\t%s\t%s\t%s\n",$1,$3,$4,$5,$6,$7) /dcos/eis/log/busted2
~

/dcos/eis/log/busted2 looks like this...

+1 LRT243 Out 03/06/07 06:31 Yantis, Gene:S990GY1 334
+2 LRT170 Out 03/06/07 06:38 Gutierrez, Ranae:S990RG5 331
+3 OTHPLM185 Out 03/06/07 06:39 Garvey, Brian:S990BG4 335
+4 OTHPLM184 Out 03/06/07 06:43 Garvey, Brian:S990BG4 335
+5 OTHPLM182 Out 03/06/07 06:45 Byers, Charles:S990CB9 335
+6 SPEC851 Out 03/06/07 06:46 Byers, Charles:S990CB9 335
+7 OTHPLM186 Out 03/06/07 06:49 Martino, Ryan:S990RM6 335
+8 SPEC848 Out 03/06/07 06:49 Martino, Ryan:S990RM6 335
+9 SPEC854 Out 03/06/07 06:54 Martino, Ryan:S990RM6 335
 
The printf was meant to replace your third print statement, like so:
Code:
awk 'BEGIN { print "Equip          DATE          TIME            LAST               FIRST S990"
            print "-----          ----          ----            ----               ----------"}
{printf ("%-10s\t%s\t%s\t%s\t%s\t%s\n",$1,$3,$4,$5,$6,$7)}' /dcos/eis/log/busted2

- Rod





IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top