Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell command on awk variable -- help 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
My awk script:

Code:
bpimagelist -l -d 12/12/2007 -M uhilhr03 | grep ^IMAGE | awk 'BEGIN {OFS=":"}{print $2, $11, $20, $19}'

I would like to take variable $19 and run the following shell command on it:

Code:
bpdbm -ctime $19

Then plug that ouput back into my awk program and get the results ... is this possible?
 
gnu awk allows this type of operation fairly elegantly through getline and any awk that has a system function can be made to exec external programs with internal variables as arguments.
 
macd68,

So after having executing an external program using the system function targeting an internal variables; can I redirect that system function's output to overwrite the same internal variable?
 
No. You can use getline with a compliant awk.
Code:
  if (cond) {
          cmd | getline var
          $FLD = var
  }
  print
}
 
From one Netbackup admin to another, I think you might be going about this the wrong way...

bpimagelist, at least on my version of it, doesn't have a variable at $19 that you can convert properly using the -ctime option of bpdbm...at $19, it's Kilobytes. What you most likely want is either $14 or $16, and there is a simple command in Gnu Awk to format that into a value you want...
Code:
bpimagelist -l -d 12/12/2007 -M MASTERSERVER | grep ^IMAGE | awk 'BEGIN {OFS=":"}{print $2, $11, $20, strftime("%c",$19)}'
There are some detailed man pages for strftime that will let you format it into the way you want to see it.
 
Code:
bpimagelist -l -d 12/12/2007 -M MASTERSERVER | awk 'BEGIN {OFS=":"} /^IMAGE/ {print $2, $11, $20, strftime("%c",$19)}'

UUOG atrocity deleted. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top