Sam*_*ynn 4 command-line bash scripts awk
I have this command
Here
vovar=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?
You used vovar
outside single quotes for the first time, but not the second time:
... awk '/'"$vovar"'/,/}/ {gsub("$vovar"," ") ...
Run Code Online (Sandbox Code Playgroud)
If you'd been consistent:
$ awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' foo
ciscoFlashCopyStatus
: %s: %s,
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5700 次 |
最近记录: |