- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk 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
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
тАО03-22-2007 01:24 AM
тАО03-22-2007 01:24 AM
awk question
thanks
Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 01:37 AM
тАО03-22-2007 01:37 AM
Re: awk question
could you give an example, otherwise it is:
echo "a b" | awk -F' ' '{print $2}'
This will print "b", which is the second field.
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 01:40 AM
тАО03-22-2007 01:40 AM
Re: awk question
You can set a different seperator in the script with IFS, or on the command line with -F. Check the man page.
And... 'skipping fields' works fine for all of us, so it is somethign you are not doing correctly.
With that out of the way....
What does you input look like ?
(attach .txt file if need be, or click 'Retain format')
What should the output look like?
What are the triggers, filters, replaces?
Hope this helps some,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 01:44 AM
тАО03-22-2007 01:44 AM
Re: awk question
Quite possible.
cat input | awk '{print $3 $4}'
This approach assumes the data file is consistent.
Otherwise you are best to read the data into variables and make decisions with logic after the data is read.
# read into variable called DATALINE
datavar1=$(echo $DATALINE | awk '{print $1}')
This puts the awk results in $datavar1 after wich logic and decision trees can be used.
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
тАО03-22-2007 02:13 AM
тАО03-22-2007 02:13 AM
Re: awk question
when I run bdf, the output of some mounts roll over to 2 lines kind of like below. This makes it hard to pull out the data that I want so I want to say remove all $1 fields that start with /. What I've been doing so far is bdf -l | grep ^/ and then I want to "remove" $1 so that all lines are equat. Does that make sense? Thanks
/dev/central03/lvol8
26% /CENTRAL-BKP/backup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 02:22 AM
тАО03-22-2007 02:22 AM
Re: awk question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 02:26 AM
тАО03-22-2007 02:26 AM
Re: awk question
There is no need to 'grep' with 'awk'. Awk has regular expression pattern matching built-in.
Consider:
# awk '{if ($1~/#/) {next} else {print}}' /etc/hosts
...would skip all comments in '/etc/hosts' by matching the "#" in the first field.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 02:29 AM
тАО03-22-2007 02:29 AM
Re: awk question
Do you really think you are the first one to tackle this!?
Just google for 'awk bdf' and you'll find oodles of solutions. No point re-inventing the wheel!
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1024204
>> What I've been doing so far is bdf -l | grep ^/ and then I want to "remove" $1 so that all lines are equat. Does that make sense?
Since you asked... No, this makes not sense.
Why would you go through grep when awk will happily do any filter work for you right there?
Why not add the extra segment to the partial to recreate a single full line and have all information?
Best regards,
Hein.
btw... do you now see why I suggested to checkmark the box before 'Retain format' just above the [submit]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 02:30 AM
тАО03-22-2007 02:30 AM
Re: awk question
if you want to print from $2 and the rest of the fields of each line - without worrying about the number of fields, you can try this:
$ awk '$1="";{print $0}' infile
(awk connoisseurs will probably find it ugly..)
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 02:46 AM
тАО03-22-2007 02:46 AM
Re: awk question
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1048509
quick and dirty way to print equal number of fields from the output of bdf -l try the awk construct below:
# bdf -l | awk '{if(NF==1) getline l;gsub(" +"," ",l);print $0l}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 03:45 AM
тАО03-22-2007 03:45 AM