- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- print a blank field $3
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
тАО02-09-2009 07:56 AM
тАО02-09-2009 07:56 AM
I want to print a blank field from a row:
ie:
ent0 Available 0G-20 4-Port
ent1 Available 0G-20 4-Port
ent2 Available 0G-20 4-Port
ent3 Available 0G-20 4-Port
ent8 Available Virtual
ent9 Available Virtual
ent12 Available VLAN
I was thinking something along the line of:
cmd |awk 'NR>2 {if ($3 ~ /..-../) $3 = "[ ]"};{print $1,$2,$3,$4}'
ent0 Available 0G-20 4-Port
ent1 Available 0G-21 4-Port
ent2 Available 0G-30 4-Port
ent3 Available 0G-31 4-Port
ent8 Available Virtual
ent9 Available Virtual
ent12 Available VLAN
how do I assign a blank field to $3?
Thanks for any help!
Chris.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 08:05 AM
тАО02-09-2009 08:05 AM
SolutionI suppose you are looking for:
# cmd | awk 'NR>2 {if ($3 ~ /..-../) $4=$3;$3=""};{print $1,$2,$4}'
...that is you move field-3 to field-4 and empty field-3. IF there were more down-stream fields you would need to push them too.
What exactly are your trying to do?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 08:11 AM
тАО02-09-2009 08:11 AM
Re: print a blank field $3
Does 'cmd' give fixed column style output?
That gets's lost in the ITRC posting, but will also be lost to AWK as it splits fields treating multiple space as one.
But anyway...
For starters, you probably wanted NF (number of fields) > 2, not NR.
And you want to test whether the anticipated 3rd fields actually looks like one, and if it does NOT, then you need to make $4 wat is seen as $3 and add a fresh $3:
awk 'NF > 2 {if ($3 !~ /..-../) {$4 = $3; $3 = "[ ]"}};{print $1,$2,$3,$4}' tmp.txt
Be sure to attach a TEXT file with the sample input if further help is needed.
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 08:51 AM
тАО02-09-2009 08:51 AM
Re: print a blank field $3
I am trying to process information from a command that has multiple fields but I am only interested in the first 4.
The I will pipe through to a while loop and run different commands depending on the device type etc:
eg
$ lstcpip -adapters
Ethernet adapters:
ent0 Available 0G-20 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent1 Available 0G-21 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent2 Available 0G-30 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent3 Available 0G-31 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent4 Available 07-20 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent5 Available 07-21 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent6 Available 07-30 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent7 Available 07-31 4-Port 10/100/1000 Base-TX PCI-X Adapter (14101103)
ent8 Available Virtual I/O Ethernet Adapter (l-lan)
ent9 Available Virtual I/O Ethernet Adapter (l-lan)
ent10 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent11 Available Shared Ethernet Adapter
ent12 Available VLAN
ent13 Available VLAN
ent14 Available VLAN
ent15 Available VLAN
lstcpip -adapters |awk 'NR>2 {print}' |while read ENT STATE HW LINE
do
if [[ -n ${HW} ]] ; then
SPEED=`lsdev -dev ${ENT} -attr media_speed`
fi
if [[ ${VLAN} -eq "VLAN" ]] ; then
VLANID=`lsdev -dev ${ENT} -attr |awk '/vlan_tag_id/ {print $2}'`
fi
and so on .....
done
~
This just the start of my code and your examples have helped.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 09:03 AM
тАО02-09-2009 09:03 AM
Re: print a blank field $3
lstcpip -adapters |awk 'NR>2 {if ($3 ~ /..-../) $4=$3;$3=""};{print $1,$2,$4}' |while read ENT STATE HW VLAN
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 09:09 AM
тАО02-09-2009 09:09 AM
Re: print a blank field $3
but the syntax will come in handy for the future
:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 09:09 AM
тАО02-09-2009 09:09 AM