- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk print question
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
11-20-2001 02:00 PM
11-20-2001 02:00 PM
FileName Tape#REC# RptName Date and the last field is comments variable length with words. The file is not delimited. I know how to use the printf sequence in awk to format the output for it to look nice, but the last field is comments and could be any number of words or stuff. Is there a way in awk to say use $5, etc ... till the end of the record and print it as one field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2001 02:25 PM
11-20-2001 02:25 PM
Re: Awk print question
awk '{for (i = NF; i > 4; i--) print $i}'
Good Luck,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2001 02:38 PM
11-20-2001 02:38 PM
SolutionThis "one-liner" awk program should do the trick for you:
awk '{ rest=""; for (ix = 5; ix <= NF; ix++) { rest = rest " " $ix } printf("%-10.10s %-10.10s %-10.10s %-10.10s %s\n",$1,$2,$3,$4,rest) }'
You may change the %-10.10s format to something that gives you a better aesthetic result.
Hope it helps,
Paga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2001 02:42 PM
11-20-2001 02:42 PM
Re: Awk print question
Try this way.
If your file is called my_text and the first four fields are fixed (say by "space") then you would do like this
awk '{print substr($0, index($0,$4)) }' my_text
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2001 03:05 PM
11-20-2001 03:05 PM
Re: Awk print question
A small correction. Make it $5 in the above awk statement otherwise it will print $4 + the comments.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2001 08:41 AM
11-21-2001 08:41 AM
Re: Awk print question
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2001 08:52 AM
11-21-2001 08:52 AM
Re: Awk print question
Probably it would have helped if you provided a sample input file.
If your input file is like this
testfile 23#1212 test.report 11/12/01 this is ofcourse my comment
Then
awk '{print substr($0, index($0,$5)) }' input_file
will print out
this is ofcourse my comment
It's a very simple logic that we are printing the substring starting from $5 (this) no matter what spaces or characters are there later. You don't have to deal with the formatting.
-Sri