![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to store the values in a file into an array | risshanth | UNIX for Dummies Questions & Answers | 3 | 01-22-2008 06:34 AM |
| To store the output in a variable | Sudhakar333 | Shell Programming and Scripting | 2 | 07-10-2007 05:45 AM |
| Need to get pid of a process and have to store the pid in a variable | samudha | UNIX for Dummies Questions & Answers | 5 | 06-11-2007 03:27 AM |
| store awk results in a variable | forever_49ers | Shell Programming and Scripting | 1 | 09-19-2006 07:51 PM |
| how do I store the values in array using shell | krishna | UNIX for Advanced & Expert Users | 2 | 08-17-2001 06:49 PM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi,
Can you please help me of how to store the values into variables. Here is the output in LINUX for the below command. $free output : total used free Mem: 3079276 3059328 19948 Swap: 1023992 6324 1017668 while i am trying the below commands i got the ouput free |grep "Mem:" |awk ' {print $2}' output for the above cmd is printing == 3079276 similar to the swap as well.. But i want to store the ouput value in a variable I also decalred the variable like this $Memory=`free |grep "Mem:" |awk ' {print $2}'`; print "$Memory "; It is printing like this Mem: 3079276 3059328 19948 Can anyone please help me regarding this how to store the values into variables.... ![]() |
| Forum Sponsor | ||
|
|
|
|||
|
$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' |