- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Stuck on Awk Statement
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
Discussions
Discussions
Forums
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
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
тАО10-07-2009 11:17 AM
тАО10-07-2009 11:17 AM
I have an input file that looks like:
1234-1234-123-12-1234-11234-123
I am using the "-" as my field separator. I can get the first 3 fields using something like, cat myfile | awk -F- '{ print $1 $2 $3 }'
But I want to treat the 4th,5th,6th and 7th field as one field.
so I would end up with four fields.
$1 $2 $3 [$4 $5 $6 &7]
did I explain that correctly.
well anyway, I cant figure it out and I really did give it a go. any help appreciated
thanks
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2009 11:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2009 12:41 PM
тАО10-07-2009 12:41 PM
Re: Stuck on Awk Statement
Cool part here is the delimiter.
-F"-"
Want to look at a passwd file, use :
Almost any delimiter can be used. The default for awk is spaces.
awk is a good friend of the sysadmin. Great power.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2009 05:56 PM
тАО10-07-2009 05:56 PM
Re: Stuck on Awk Statement
>>did I explain that correctly.
Yes you did, in awk $1 means 1st filed $2 means 2nd field and so on
and $0 is for hole line
in your awk you can do is like this way also
$ awk -F "-" '{ print $1" " $2" " $3}'
to know more about awk see the below link
http://www.ibm.com/developerworks/library/l-awk1.html
http://www.ibm.com/developerworks/library/l-awk2.html
http://www.grymoire.com/Unix/Awk.html
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2009 05:10 AM
тАО10-08-2009 05:10 AM
Re: Stuck on Awk Statement
$ echo "1234-1234-123-12-1234-11234-123" | \
perl -ne \
'print join(" ", split(/-/, $_, 4));'
1234 1234 123 12-1234-11234-123
$
This can handle an arbitrary number of fields - the "4" as the last argument of split designates the total number of split fields, encompassing the entire remainder of the line in the fourth.
Awk was first written in 1977, and needless to say its capabilities and idiosyncrasies such as the $1 $2 .. $n notation, among many other useful sysadmin tools, inspired Larry Wall's original architecture of Perl in 1987.