The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-05-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
$2 in the awk script probably gets substituted with something unexpected when you evaluate it in backticks in Perl. $2 in Perl is the result of the second set of parentheses in the latest regular expression match; presumably it's empty, so the awk script is just "print".

Quote the variable properly, and it should work.

Note, though, that you have a Useless Use of Grep when you pipe to awk -- awk can grep just fine. And by the same logic, I guess it's a Useless Use of Awk to call awk from Perl, because Perl can do everything awk can, only better.

Code:
perl -e '$mem = `free`; $mem =~ s/.*Mem:\s+(\d+)\s.*/$1/s'
The /s option causes .* to match across newlines, so you can handle the multiple lines of output from free as one expression.
Reply With Quote