List Certain Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List Certain Output
# 1  
Old 09-22-2011
List Certain Output

Hi Expert,

I have a text file that contain the following data
Code:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1397  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/28]
john      1398  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/29]
john      1399  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/30]
ruby         7  0.0  0.0      0     0 ?        S<   Jul14   0:00 [watchdog/1]
root         8  0.0  0.0      0     0 ?        S<   Jul14   0:01 [migration/2]
jane         9  0.0  0.0      0     0 ?        SN   Jul14   0:00 [ksoftirqd/2]
john        10  0.0  0.0      0     0 ?        S<   Jul14   0:00 [watchdog/2]
root        11  0.0  0.0      0     0 ?        S<   Jul14   0:01 [migration/3]

Now, what I want is to list just user john and ruby with certain header, e.g:
Code:
USER       PID %CPU %MEM     TTY    STAT TIME COMMAND
john      1398  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/29]
john      1399  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/30]
ruby         7  0.0  0.0      0     0 ?        S<   Jul14   0:00 [watchdog/1]

How do I do that? with awk?

Thank you Expert.

Last edited by Scott; 09-22-2011 at 01:20 AM.. Reason: Code tags, please...
# 2  
Old 09-22-2011
Code:
$ egrep "^USER|^john|^ruby" infile

# 3  
Old 09-22-2011
Code:
$ nawk '/USER|john|ruby/' filename
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
john      1398  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/29]
john      1399  0.0  0.0      0     0 ?        S<   Jul14   0:00 [aio/30]
ruby         7  0.0  0.0      0     0 ?        S<   Jul14   0:00 [watchdog/1]
john        10  0.0  0.0      0     0 ?        S<   Jul14   0:00 [watchdog/2]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files output only for the last line

Hi, "ls -tl directory1" will list files to be sorted in mtime, but I don't want to see all the files in each directory, I want to only see output the last line (the oldest mtime) for each directory. $ ls -tl test1 -rw-r--r-- 1 hce hce 1714397 May 30 2013 b.txt -rw-r--r-- 1 hce hce 4678 May... (2 Replies)
Discussion started by: hce
2 Replies

2. Shell Programming and Scripting

How to process select list of files and output to the same file?

Hi, I've a list of files ac_info.tps, subscription_array.tps, .......and many other files one of the file, bin_range_list.tps has the following content CREATE OR REPLACE TYPE "BIN_RANGE_LIST" AS TABLE OF BIN_RANGE_ELEM; / grant execute on... (4 Replies)
Discussion started by: jediwannabe
4 Replies

3. Shell Programming and Scripting

Duplicate files and output list

Gents, I have a file like this. 1 1 1 2 2 3 2 4 2 5 3 6 3 7 4 8 5 9 I would like to get something like it 1 1 2 2 3 4 5 3 6 7 Thanks in advance for your support :b: (8 Replies)
Discussion started by: jiam912
8 Replies

4. UNIX for Advanced & Expert Users

[Solved] mpathadm list lu no output

When I try to configure my HBA ports on Solaris 10; I cant see any output. bash-3.2# mpathadm list lu bash-3.2# I checked /kernel/drv/fp.conf file. ... mpxio-disable="no"; ... What shall I check more? what shall I do? ---------- Post updated at 10:18 AM ---------- Previous update was... (0 Replies)
Discussion started by: hubatuwang
0 Replies

5. Shell Programming and Scripting

Output file list to array?

Hey, guys, scripting newb here. I'm trying to get a list of all .dmg files in a folder and save the output into an array. My first attempt was ARRAY= ( `ls $REIMAGEPATH | grep \.dmg$` ) However, I understand why that doesn't work now (at least I think I do). But I don't know what the... (5 Replies)
Discussion started by: nextyoyoma
5 Replies

6. Shell Programming and Scripting

list files command output

Hi All, Below is the 2 different ouputs of the command "ls -lrt", my question is what exactly "total 0" & "total 8" means here ? $ ls -rtl total 0 -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 c -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 b -rw-r--r-- 1... (1 Reply)
Discussion started by: kannan84
1 Replies

7. Shell Programming and Scripting

Need your help to get the output of the list in desired format

Hello Guys, I am working on a script and using the below code to fetch the list of all repositories CHDIR='/mnt/scm/subversion/' repolist() { cd ${CHDIR} Repo=`ls|cut -d " " -f1` echo $Repo } Output of the above code is BSB CIB COB DCI DIB DSB ESB-P ESB-TOOLS FareVerify GCACHE GWY... (15 Replies)
Discussion started by: rohit22hamirpur
15 Replies

8. Shell Programming and Scripting

Output of command in comma separated list

Hi; I have an output of a particular command say $command fstl:r-x ajay:r-x how can i get this in comma separated list, eg: fstl:r-x,ajay:r-x Thnks; (4 Replies)
Discussion started by: ajaypadvi
4 Replies

9. Shell Programming and Scripting

how to suppress list number from history command output

i run history command and I want to eliminate the list number. So far this perl script works as long as the list is a exact 3 character long. cat dd | perl -pe 's,\d{3},,' 70 export JAVA_HOME=. 81 export JAVA_HOME=. 82 export JAVA_HOME=`pwd` export JAVA_HOME=`pwd` ... (1 Reply)
Discussion started by: soemac
1 Replies

10. Shell Programming and Scripting

script to list out the output in one paragraph

Hi All, I want to run 5 `ps -ef | grep ` cmds in one script and i want the script to give me return code 0 if everything is OK. If it notices one of the processes is not there, it will prompt me the process name and advice me to check it. I've wrote a script that separates the output but I want... (2 Replies)
Discussion started by: fara_aris
2 Replies
Login or Register to Ask a Question