Passing Variable into awk gsub
6,147
You used vovar
outside single quotes for the first time, but not the second time:
... awk '/'"$vovar"'/,/}/ {gsub("$vovar"," ") ...
If you'd been consistent:
$ awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' foo
ciscoFlashCopyStatus
: %s: %s,
Related videos on Youtube
Comments
-
SamFlynn over 1 year
I have this command
Herevovar=OBJECTS prvar="$(awk '/'"$vovar"'/,/}/ {gsub("$vovar"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' temp1)"
Contents of temp1
ciscoFlashCopyCompletionTrap NOTIFICATION-TYPE OBJECTS { ciscoFlashCopyStatus } STATUS current DESCRIPTION "A ciscoFlashCopyCompletionTrap is sent at the completion of a flash copy operation if such a trap was requested when the operation was initiated. " ::= { ciscoFlashMIBTraps 1 }
What I want the command to do
ciscoFlashCopyStatus : %s: %s,
What it actually does
OBJECTS ciscoFlashCopyStatus : %s: %s,
How can I change my awk command so that I can get what I want?
-
Avinash Raj almost 9 yearsuse
-v
param to pass variables into awk. -
SamFlynn almost 9 yearsYep! tried that already. Still getting the same output with OBJECTS written in the first line.
-
-
SamFlynn almost 9 yearsAh damn it. Sorry about this.
-
A.B. almost 9 yearsYou are too fast for me ;)