Formatting the output of ps -eo command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting the output of ps -eo command
# 8  
Old 08-02-2012
Strange ... if I do (disregard me testing $1 instead of $5) result is:
Code:
# ps |awk '{if($1>=5) {$1=$1; found=1; print}} END {exit !found}' OFS="\t"; echo "exit code: "$?  
5       S       root    972     1       ...
5       S       root    1504    1       ...
exit code: 0
# ps |awk '{if($1>=6) {$1=$1; found=1; print}} END {exit !found}' OFS="\t"; echo "exit code: "$?
exit code: 1

So my awk version must differ from yours. What be your version? And - please split all the awk commands into separate lines like
Code:
ps ...  |awk '
{if($5>=2)
 {$1=$1;
  found=1;
   print}}
END {exit !found}'

so we'll get an indicator on what's wrong.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 08-02-2012
Sorry may sound dumb but how to you find out the version of
Code:
awk

you are using?

And Ive broken the code down into seperate lines as suggested above and received this response

Code:
awk: syntax error near line 6
awk: illegal statement near line 6

# 10  
Old 08-02-2012
Try awk -W version. And then, read your awk's man page about the exit command. Here's an excerpt from mine:
Quote:
exit opt_expr
An exit statement causes immediate execution of the END actions or program termination if there are none or if the exit occurs in an END action. The opt_expr sets the exit value of the program unless overridden by a later exit or subsequent error.
# 11  
Old 08-02-2012
found this in the man pages for awk

Code:
exit [expr]     # skip the rest of the input; exit status is expr

cant find the version though using your code above
# 12  
Old 08-02-2012
one - try exit found (=leave out "!") so we find out if it doesn't like the negation
two - the man page should give you an indication on how to output the version
# 13  
Old 08-02-2012
ive looked thorugh the man pages and cant find anything on how to tell which version of awk im using however I did see a mention of POSIX locale if that heps at all.

Im now getting the following so it seems to be working just need to get it to put a tab space and not the backslash between fields

Code:
ps -eo pri,pid,user,nice,pcpu,comm | awk '{if($5>=5) {$1=$1; found=1; print}} END {exit found}' OFS="\t"; echo "exit code: "$? 
20\10833\root\20\12.4\/apps/progress//bin/_progres
30\14631\root\20\10.7\_progres
20\19628\root\20\10.5\_progres
exit code: 1

# 14  
Old 08-02-2012
OK, we're getting there. Looks like your awk is a bit delicate. Modify your awk line like
Code:
awk 'BEGIN {found=1} {if($5>=5) {$1=$1; found=0; print}} END {exit found}' OFS="        ";

Make sure to enter a <TAB> char for OFS, in the shell (bash!?) by prepending it with <CTRL>V (or do it in an editor).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output formatting

Hi , can anyone help me in this Input file Name= XYZ Company= ALPHA City= Stockhomn Equipment=computer Country=Sweden Name=MNC Company=Beta City=Kaulampur Equipment=computer Country=Malaysia Name=JVC Company=gamma City=Kiruna (3 Replies)
Discussion started by: swets
3 Replies

2. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

3. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

4. Shell Programming and Scripting

Output formatting .

below is a CPU utilization Log for ABC server. However for every 15 minutes it generates 3 CPU values(with interval of 2 sec). Host CPU CPUtotal CPU% time ABC 101.1 2 50.55 14 : 15 ABC 100.5 2 50.25 14 : 15 ABC 100.2 2 50.1 14 : 15 ABC 100.9 2 50.45 14 : 30 ABC 100.5 2 50.25 14 : 30 ABC... (5 Replies)
Discussion started by: pinga123
5 Replies

5. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

6. Shell Programming and Scripting

formatting output

my script is as follows cnt=`ps -ef |grep pmon|grep -v grep|awk 'END {{print NR}}'` cnt2=`ps -ef |grep tns|grep -v grep|awk 'END {{print NR}}'` if then if then rman target/ catalog recdb/recdb@recdb cmdfile report_need_backup.sql > report_need_backup.txt ... (1 Reply)
Discussion started by: swkambli
1 Replies

7. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

8. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

9. Shell Programming and Scripting

Formatting output

Hi, I am new to shell scripting, I ahve written a shell script which would extract me data, but my problem is I want to add a column name to my output. Using grep and sed I am getting my data from the input file. Sample data name : eric name : tom name : sean My output using grep and sed... (3 Replies)
Discussion started by: illur81
3 Replies

10. Shell Programming and Scripting

Formatting the output

Hi all, Have the following code(1) producing the results(2 & 3). Would like to know if there is a way to format the two reports created in a similar fashion. IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt However when I attempt to do the same on... (7 Replies)
Discussion started by: Cameron
7 Replies
Login or Register to Ask a Question