4

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?

2
  • use -v param to pass variables into awk. Jun 30, 2015 at 4:29
  • Yep! tried that already. Still getting the same output with OBJECTS written in the first line.
    – SamFlynn
    Jun 30, 2015 at 4:32

1 Answer 1

5

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,
2
  • 1
    Ah damn it. Sorry about this.
    – SamFlynn
    Jun 30, 2015 at 4:46
  • You are too fast for me ;)
    – A.B.
    Jun 30, 2015 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.