![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| insert a line after specific line | namishtiwari | Shell Programming and Scripting | 8 | 05-21-2008 03:16 PM |
| Adding a columnfrom a specifit line number to a specific line number | Ezy | Shell Programming and Scripting | 2 | 05-12-2008 09:29 AM |
| printing the next line too?? | AndyA | Shell Programming and Scripting | 6 | 01-31-2008 06:35 AM |
| Printing Dots in specific Locations in the Console ? | Max_Payne | High Level Programming | 0 | 01-13-2008 12:57 AM |
| Printing lines with specific awk NF | jehrome_rando | Shell Programming and Scripting | 1 | 03-13-2007 04:23 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Printing a specific line using AWK
Hi,
I have a script that fetches only specific information from fcinfo command. Below is a portion of the script. #!/usr/bin/ksh set -x HBA_COUNT=`sudo fcinfo hba-port | grep -i state | awk 'END{print NR}'` echo "$HBA_COUNT HBAs exist" echo '........' INDEX=1 while [wiki] $INDEX -le $HBA_COUNT [/wiki] ; do HBA_STAT[$INDEX]=`sudo fcinfo hba-port | grep -i 'Port WWN' | awk 'NR==$INDEX' | awk '{print $NF}'`done The part in red is where I'm having trouble with. When I type sudo fcinfo hba-port | grep -i 'Port WWN' | awk 'NR==1' | awk '{print $NF}' into the command line, I have no problem displaying the WWN info (where the value in blue can vary). Also, I noticed something funny where if i replace (in the script) HBA_STAT[$INDEX]=`sudo fcinfo hba-port | grep -i 'Port WWN' | awk 'NR==$INDEX' | awk '{print $NF}'` with HBA_STAT[$INDEX]=`sudo fcinfo hba-port | grep -i 'state' | awk 'NR==$INDEX' | awk '{print $NF}'` it still doesn't work, but once I change 'NR==$INDEX' with '$NR==INDEX', it works... Can someone explain why this is happening and maybe correct me on the syntax if I'm doing something wrong? Thanks |
|
||||
|
The shell don't expand shell variables within single quotes, try this: Code:
HBA_STAT[$INDEX]=`sudo fcinfo hba-port | grep -i 'Port WWN' | awk 'NR=='$INDEX | awk '{print $NF}'`
or with a awk variable: Code:
HBA_STAT[$INDEX]=`sudo fcinfo hba-port | grep -i 'Port WWN' | awk -v var=$INDEX 'NR==var' | awk '{print $NF}'`
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|