Display Additional Variable string in awk print command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display Additional Variable string in awk print command
# 1  
Old 04-04-2013
Display Additional Variable string in awk print command

Hi all,
I have script to monitor and sum up the total memory use up for each individual process.
Code:
proc=$1
svmon -P -O summary=basic,unit=MB|awk 'NR>4'|grep -w "${proc}" |awk '{sum+=$3} END {printf "\t" sum """\n";}'


But I would like the script to be able to display as following

Execute
------
Code:
 ./script java

Output
-----
Code:
  java -> 1233

Can anyone has bright idea on this ?

Thanks.

Last edited by Franklin52; 04-04-2013 at 07:17 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 04-04-2013
Please use code tags

Code:
... | awk '{sum+=$3} END {printf pname"->" sum "\n";}' pname=$proc

--ahamed

---------- Post updated at 01:08 AM ---------- Previous update was at 01:01 AM ----------

See if this helps to reduce the code
Code:
proc=$1
svmon -P -O summary=basic,unit=MB | awk '/'$proc'/&&NR>4{sum+=$3} END {printf pname"->" sum "\n";}' pname=$proc

--ahamed

Last edited by ahamed101; 04-04-2013 at 06:10 AM..
# 3  
Old 04-04-2013
thanks Ahamed, yes this is working. And thanks for instant reply.

---------- Post updated at 07:56 PM ---------- Previous update was at 03:32 AM ----------

Hi Ahmed, just realize that the sum of one of the process call "sh" in fact, it sum out together the rest of the "ksh", "ksh" etc of Inuse values. Could you just match exact string in awk comparison ? thanks
# 4  
Old 04-05-2013
If you can provide the output of svmon..., then we can try to do a column match, else we need to traverse the entire line for a exact match field by field check.

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. UNIX for Advanced & Expert Users

Pass variable to awk command search string

I must have forgot how to do this, but, I am attempting to enter a variable into an awk / gawk search pattern. I am getting a value from user input to place in a specific section of a 132 character string. my default command is .... gawk --re-interval '/^(.{3}P .{4}CYA.{8}1)/' ... (3 Replies)
Discussion started by: sdeevers
3 Replies

3. Shell Programming and Scripting

awk print variable then fields in variable

i have this variable: varT="1--2--3--5" i want to use awk to print field 3 from this variable. i dont want to do the "echo $varT". but here's my awk code: awk -v valA="$varT" "BEGIN {print valA}" this prints the entire line. i feel like i'm so close to getting what i want. i... (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

Variable interpolation in "print" of awk command

Hi, I have a snippet like below. Based on variable i, i wish to print 1,2,3,4,5th columns to Sample files. For each loop, one column from contetn and results will be pused to sample files. But i have a problem here i=1 while ; do `awk -F"\t" '{print $($i)}' $content > Sample_${i}_original`;... (4 Replies)
Discussion started by: forums123456
4 Replies

6. Shell Programming and Scripting

awk print using a variable

hey, just want to ask how to do this. ex. g="hi i am john" h=`echo $g | awk '{print $2}'` echo $h OUTPUT is 'i' What if I want to use a variable instead of using '2', how do I do that? Because this one does not work: a=2 h=`echo $g | awk '{print ${$a}}'` this one also does not... (3 Replies)
Discussion started by: h0ujun
3 Replies

7. Shell Programming and Scripting

awk print variable

I have list of files: ls a.pdf b.pdf c.pdf and so on... and I have a file like this: cat file1 apple mango pear and so on... I want to rename my file like this: (7 Replies)
Discussion started by: zorrox
7 Replies

8. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

9. Shell Programming and Scripting

awk help..string display

Dear All I had input file as mention below. <RXMFP:MO=RXOTX-46-5; RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT INFORMATION MO BTSSWVER RXOTX-46-5 ERA-G04-R11-V01 RU RUREVISION RUSERIALNO 0 RUPOSITION ... (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

10. UNIX for Advanced & Expert Users

Command to display nth line before the string is matched.

All, Is there any way out to display the nth line before the string is matched ??? Eg : If i have a file which has the following contents and if i want to get the 3rd line before the string is matched a b c d e f if i give the input as f and lines before the match as 3 then it should... (5 Replies)
Discussion started by: helper
5 Replies
Login or Register to Ask a Question