Arrange output of a command


 
Thread Tools Search this Thread
Operating Systems Linux Arrange output of a command
# 1  
Old 02-22-2016
Arrange output of a command

Hi,

I am using a command :-
Code:
 ps -auxwww 2> /dev/null | awk 'match ($0, GIN:[^ ]*/) {print substr($0, RSTART+3, RLENGTH-3)}' | sort |  grep -v -F '[^' | uniq

which gives output as
Code:
   
3 aruau
5 asun
4 cgan

Now I need a command which gives me something like this :-
Code:
   
3 aruau
5 asun
4 cgan
Total 12


Last edited by Raj999; 02-22-2016 at 06:53 AM..
# 2  
Old 02-22-2016
Hello Raj999,

As you haven't showed us the complete sample input of ps -auxwww. So following may help you in same though we could make it more simpler within single awk etc.
Code:
Your_previous_command(which I haven't tested/tried) | awk '{SUM+=$1;print} END{print "Total " SUM}'

Please let us know if you have any queries with complete sample inputs and output of ps -auxwww.

Thanks,
R. Singh

Last edited by RavinderSingh13; 02-22-2016 at 07:11 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 02-22-2016
Your match can't possibly work as the regex is not correctly delimited. And, in your output, the colon is missing that the substr should select due to RLENGTH+3 (instead if e.g. 4).

With some assumptions from my part, try
Code:
ps -auxwww 2> /dev/null | awk 'match ($0, /GIN:[^ ]*/) {C[substr($0, RSTART+3, RLENGTH-3)]++; SUM++} END {for (i in C) print C[i], i; print "Total:", SUM}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to arrange words

Hi I have a text file as given below: Input format I have a text file as given below . This is a (9 Replies)
Discussion started by: my_Perl
9 Replies

2. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

3. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

4. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

5. Shell Programming and Scripting

Arrange output based on rows into columns

Hi All, I would like to ask help on how can i achieve below output. Inputfile: Oct11,apa1-daily,01:25:01 Oct11,apa2-daily,01:45:23 Oct12,apa1-daily,02:30:11 Oct12,apa2-daily,01:55:01 Oct13,apa1-off,01:43:34 Oct13,apa2-off,01:22:04 Desired output: Clients ... (3 Replies)
Discussion started by: mars101
3 Replies

6. Shell Programming and Scripting

Re-arrange column

10.142.7.155 - - www.abc.com 404 - I have many columns which is tab delimited file, I have to re-arrange this to a particular column and also add "-" to 3rd column and 6th column. 10.142.7.155 - - - www.abc.com - 404 - (4 Replies)
Discussion started by: sandy1028
4 Replies

7. UNIX for Dummies Questions & Answers

Arrange data

I have a following data: 100 200 300 400 I want the data to be arranged: 100 200 300 400 What is the best way to do this? Thanks! (5 Replies)
Discussion started by: bobo
5 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. UNIX for Dummies Questions & Answers

how to sort and arrange an output

ok so I have a list of names that end in either ot,om,oa. So for example DETOT MANOA DET0M DET0A MANOT SEAOT etc... I want to be able to group this list by OT, OM, OA and have the output have some headers like this and be alphabatized and if possible be in colums instead of like... (10 Replies)
Discussion started by: llsmr777
10 Replies

10. Shell Programming and Scripting

re arrange the columns

Hi - can any one let me know how to re-arrange the columns of a comma seperated file. The problem here is that the colums some times have new lines and when the columns has new lines or extra comma's then it is enclosed in double quotes("). Can any one tell me how to re-arrange the columns now. ... (0 Replies)
Discussion started by: ahmedwaseem2000
0 Replies
Login or Register to Ask a Question