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?

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

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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