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!

format text file into 2 columns using awk 1

Status
Not open for further replies.

mregotman

Instructor
Mar 20, 2011
6
US
I have script that produces this result below - I'm trying to align the output into only 2 colums ..see below for the desired output. I'm using the following code, I need help tweeking it or a complete rewrite ..Thanks for any assistance.

awk '{printf("%-30s%-15s%-10s\n", $1,$2,$3,$4)}' ~/Desktop/LogReport.txt

Security and Maint Logs
========
system.log [ 42M ]
secure.log [ 522K ]
install.log [ 989K ]
windowserver.log [ 44K ]
alf.log [ 62B ]
appfirewall.log [ 68K ]
ipfw.log [ 120K ]
kernel.log [ 385K ]
fsck_hfs.log [ 96K ]
launchd-shutdown.log [ 316K ]


# Desired output
Security and Maint Logs
========
system.log [ 42M ]
secure.log [ 522K ]
install.log [ 989K ]
windowserver.log [ 44K ]
alf.log [ 62B ]
appfirewall.log [ 68K ]
ipfw.log [ 120K ]
kernel.log [ 385K ]
fsck_hfs.log [ 96K ]
launchd-shutdown.log [ 316K ]
 
oops, the desired output got jumbled up when I submitted it .. the output should look to have
the left most brackets perfectly aligned over each other ..the right brackets do not need to be aligned
just the left most brackets ..thanks in advance.
 
What is the input? Why does your printf statement 3 items in the format but 4 arguments? Post you data inside
Code:
tags and it should align better in your post.

CaKiwi
 


Try this:
Code:
awk '{printf("%-30s %15s\n", $1,$2" "$3" "$4)}' ~/Desktop/LogReport.txt
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
at LKBrwnDBA,

Nice but it aligns the right side brackets perfectly ..just the opposite of what I need ..

at CaKiwi,

Here is the full code actually ..I've aligned it fine in my out of my script ..but when I send the output
to my iphone ..the text is jumbled up


echo Security and Maint Logs
echo "${black}========${normal}"
cd /var/log
echo -e system.log "\t\t" "${purple}[${normal}" `ls -lahFSu system.log | awk '{print $5}'` "${purple}]${normal}"
echo -e secure.log "\t\t" "${purple}[${normal}" `ls -lahFSu secure.log | awk '{print $5}'` "${purple}]${normal}"
#echo -e mb.log "\t\t\t" "${purple}[${normal}" `ls -lahFSu mb.log | awk '{print $5}'` "${purple}]${normal}"
echo -e install.log "\t\t" "${purple}[${normal}" `ls -lahFSu install.log | awk '{print $5}'` "${purple}]${normal}"
echo -e windowserver.log "\t" "${purple}[${normal}" `ls -lahFSu windowserver.log | awk '{print $5}'` "${purple}]${normal}"
 

Just needs a '-':
Code:
awk '{printf("%-30s %-15s\n", $1,$2" "$3" "$4)}' ~/Desktop/LogReport.txt
[noevil]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top