- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk and printf
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 07:51 AM
01-14-2005 07:51 AM
awk and printf
I am trying to format a log file .I need a aligned 4 column o/p .Sample of the log file is attached.
I am using cat sample.txt |awk -F"|" '{printf "%10s %-20s %20-s %20-s", $1,$2,$3,$4}'
But Its not able to format the o/p in columnvice.
Can you pls help.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 08:03 AM
01-14-2005 08:03 AM
Re: awk and printf
awk -F '|' '{printf("%-10.10s %-20.20s %-20.20s %-20.20s\n",$1,$2,$3,$4)}' sample.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 08:23 AM
01-14-2005 08:23 AM
Re: awk and printf
\n I was using forgot to type .
It has not given me the required o/p .
Can you please try this on the sample.txt attached.
Thanks,
Baiju.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 08:34 AM
01-14-2005 08:34 AM
Re: awk and printf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 08:53 AM
01-14-2005 08:53 AM
Re: awk and printf
Control char might have added during copy paste to ITRC.
The o/p which I was looking for is attached .
Still no progress for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 09:37 AM
01-14-2005 09:37 AM
Re: awk and printf
Please see the attached file which contains both the script and the output.
After you yank out the script, chmod 777 my.sh and then
my.sh < sample.txt > out.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 03:03 PM
01-14-2005 03:03 PM
Re: awk and printf
You need to eat the spaces somehow.
The can be done with a replace in the 'code',
or they can be sucked into the ERE for the seperator. Try:
awk -F " *[|] *" '{printf "%10s %-20s %-20s %-20s\n", $1,$2,$3,$4}'
The ERE is
- a space followed by an asterix for zero or more spaces.
followed by
- a boxed in |. I had to do this to avoid the bar becoming an 'or'
followed y zero or more spaces.
Cheers,
Hein.