disregarding space when using awk print | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

disregarding space when using awk print

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-09-2012
prodigy06 prodigy06 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 30 July 2014, 3:05 AM EDT
Posts: 20
Thanks: 8
Thanked 0 Times in 0 Posts
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:1

I 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  
Old 10-09-2012
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 15 September 2014, 8:06 AM EDT
Posts: 1,649
Thanks: 58
Thanked 478 Times in 474 Posts
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  
Old 10-09-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 3 October 2014, 8:50 AM EDT
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts

Code:
 
$ awk '/FIBRE/&&NF==3{print $1;next}/FIBRE/{print $2}' input.txt
10000000c986cdb0
10000000c9866716

    #4  
Old 10-09-2012
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 25 October 2014, 11:55 AM EDT
Location: Aachen, Germany
Posts: 4,425
Thanks: 73
Thanked 1,082 Times in 1,020 Posts

Code:
awk '/FIBRE/ {print $(NF-2)}' inputfile

The Following User Says Thank You to RudiC For This Useful Post:
prodigy06 (10-10-2012)
Sponsored Links
    #5  
Old 10-09-2012
penchal_boddu penchal_boddu is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 11 February 2013, 3:10 PM EST
Location: Bangalore
Posts: 173
Thanks: 0
Thanked 5 Times in 4 Posts
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) }' filname


Last 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  
Old 10-09-2012
prodigy06 prodigy06 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 30 July 2014, 3:05 AM EDT
Posts: 20
Thanks: 8
Thanked 0 Times in 0 Posts
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  
Old 10-09-2012
penchal_boddu penchal_boddu is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 11 February 2013, 3:10 PM EST
Location: Bangalore
Posts: 173
Thanks: 0
Thanked 5 Times in 4 Posts

Code:
awk -F'[ -:]' '( NR>2) { print $(NF-6) , $(NF-1) , $NF  }' filename


Last edited by Scrutinizer; 10-10-2012 at 03:03 AM.. Reason: code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 11:56 AM.