How to parse 2 particular lines from Command output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to parse 2 particular lines from Command output
# 1  
Old 07-25-2011
How to parse 2 particular lines from Command output

Hi All,
I need help on the following req.
I am getting output of a command as follows:

Code:
 16377612  total memory
      3802460  used memory
      2827076  active memory
       681948  inactive memory
     12575152  free memory
       477452  buffer memory

I want to compute used (memory/total memory).
What is the possible way to parse this command output to get those two values....

your help is highly appreciated..

-Saravana

Last edited by radoulov; 07-25-2011 at 05:24 PM.. Reason: Code tags.
# 2  
Old 07-25-2011
Try:
Code:
command | awk '/total/{t=$1}/used/{print $1/t}'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to parse iostat command output

Hi, I got the code below is one of the threads from this forum. lineCount=$(iostat | wc -l) numDevices=$(expr $lineCount - 7); iostat $interval -x -t | awk -v awkCpuFile=$cpuFile -v awkDeviceFile=$deviceFile -v awkNumDevices=$numDevices ' BEGIN { print... (2 Replies)
Discussion started by: gopivallabha
2 Replies

2. UNIX for Dummies Questions & Answers

Cat command drops lines in output file

I use the cat command to concatenate text files, but one of the rows I was expecting doesn't display in the output file. Is there a verbose mode\logging mechanism for the cat command to help me investigate where the lines I was expecting are going?? cat 7760-001_1_*_06_*.txt | grep -v... (1 Reply)
Discussion started by: Xin Xin
1 Replies

3. AIX

Print output of grep command in multuple lines

HI All, I am using grep command to serach a pattern in a list of files and storing the output in a variable. Then i am applying some logic on that variable to get the required output. But Thing is that when the pattern is present mutiple times in a file, i am getting the output of grep in a... (3 Replies)
Discussion started by: goutam sahoo
3 Replies

4. Shell Programming and Scripting

Perl Parse word from command output

Hello, I used the following script to conect to cisco router: #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Opsware::NAS::Connect; my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$'); my $device =... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

5. Shell Programming and Scripting

How to cut selected lines from command output

Hi guys, I need to cut the first 12 system processes from the command ps -A. I know that the cut command forms part of the pipeline but can't understand how to cut the first 12 lines and later display them on standard output. Please help! Many thanks, Jared. (3 Replies)
Discussion started by: jjb1989
3 Replies

6. UNIX for Dummies Questions & Answers

Which command can help me output lines with duplicate numbers?

i have a file, let's call it file. march 2008 january 2008 march 1920 march 2002 i want to output the first line, not the second as you can see the second line has different numbers. (8 Replies)
Discussion started by: hobiwhenuknowme
8 Replies

7. Shell Programming and Scripting

Help required on grep command(Skip the first few lines from printing in the output)

Hi experts I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output. I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies

8. Shell Programming and Scripting

How do I capture multiple lines of the status output of a command?

I need to know what the upload speed of an Internet connection. I thought the easiest way to do this would be to transfer a file via FTP to my server using the command: sh-3.2$ ftp -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded Note: My environment allows me to issue... (2 Replies)
Discussion started by: zzz1528
2 Replies

9. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

10. Shell Programming and Scripting

Add text before lines in command output

Hi2all, I have following command in IBM HMC console: lssyscfg -r prof -m Server-9117-MMA-SN655D350 -F lpar_name,min_mem,desired_mem --header which gives me the following output: lpar_name,min_mem,desired_mem lpar1,1024,2048 lpar2,1024,2048 lpar3,2048,4096 What I want is to add in... (3 Replies)
Discussion started by: UsRb
3 Replies
Login or Register to Ask a Question