|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
disregarding space when using awk print
Hi guys, I have this output, wherein the device is variable and changing values Code:
Device Identifier Type Dir:P
------ ---------------- ----- ----------------
3065 10000000c986cdb0 FIBRE FA-10A:1
10000000c9866716 FIBRE FA-11A:1I want to filter column 2 which has wwns im using this but doesnt seem to work. please help. Code:
symmaskdb -sid $A\ -dev $D list assign | sed -e 's/$D//g' | grep FIBRE | awk '{print $1}'output is Code:
3065 10000000c9866716 and my desired output is Code:
10000000c986cdb0 10000000c9866716 |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
you don't need grep and awk separately. try this.. Code:
awk '/FIBRE/{for(i=1;i<=NF;i++){if($i == "FIBRE"){print $(i-1)}}}' file |
| The Following User Says Thank You to pamu For This Useful Post: | ||
prodigy06 (10-10-2012) | ||
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
$ awk '/FIBRE/&&NF==3{print $1;next}/FIBRE/{print $2}' input.txt
10000000c986cdb0
10000000c9866716 |
|
#5
|
|||
|
|||
|
for this specific case , searching of FIBRE may solve the issue. When searching on assignment for multiple devices , there can be devices mapped to SCSI ports or Mainframe ports . This might work better in those cases. Code:
awk '( NR>2) { print $(NF-2) }' filnameLast edited by Scrutinizer; 10-10-2012 at 03:03 AM.. |
| The Following User Says Thank You to penchal_boddu For This Useful Post: | ||
prodigy06 (10-10-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
great, all of the suggestion works! thanks everyone. can some one tell me what is NR for in awk? just for my future reference. from the output above how can i also filter my final output to be like Code:
10000000c986cdb0 10A 1 because when i print NF it displays FA-10A:1 i need to remove FA-(probably be sed or any other method), and separate 10A and 1 with space instead of a colon. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Code:
awk -F'[ -:]' '( NR>2) { print $(NF-6) , $(NF-1) , $NF }' filenameLast edited by Scrutinizer; 10-10-2012 at 03:03 AM.. Reason: code tags |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk until blank space and print next line | Gery | Shell Programming and Scripting | 2 | 01-01-2012 06:16 AM |
| Print characters till the next space when the pattern is found | gpk_newbie | Shell Programming and Scripting | 2 | 10-19-2011 05:02 AM |
| Find a pattern and print next all character to next space | pierrebjarnfelt | Shell Programming and Scripting | 8 | 05-18-2010 06:11 AM |
| way to print all the string till we get a space and a number | villain41 | Shell Programming and Scripting | 13 | 01-27-2009 02:37 AM |
| print disk space warning of 70% | itik | Shell Programming and Scripting | 1 | 10-17-2008 10:57 AM |
|
|