[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 110: Undefined array key "cached"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 111: Undefined array key "normal"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 112: Undefined array key "total"
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3391: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3393: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3394: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3395: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
Cabrillo College Linux Classes • View topic - Redirect line of output

Redirect line of output

Introduction to UNIX/Linux

Redirect line of output

Postby brynden hutmacher on Thu Nov 06, 2008 9:15 pm

How do you redirect just a line of out put from the ps -l command?
brynden hutmacher
 
Posts: 13
Joined: Wed Sep 03, 2008 7:25 pm

Re: Redirect line of output

Postby Michael Wicherski on Fri Nov 07, 2008 4:59 am

uhm

just one line?
if you wanted line 2 you could do

ps -l | head -2 | tail -n1 > file

run ps command with l option
then pipe into head and print out first 2 lines
then pipe into tail to print the last line (of 2 so line 2)
then redirect to a file
o.O

(i think that should work anyway; not too familiar with the ps command yet)

**edit/update** notice that the first line ps prints to the screen, the column titles, is also counted, so if you want the second item on the list, you actually want the third line**
Michael Wicherski
 
Posts: 140
Joined: Mon Sep 01, 2008 5:23 am

Re: Redirect line of output

Postby ollie wright on Tue Nov 11, 2008 9:56 am

I used:
ps -l | grep "13298 13266" | tee bigshell which put the line I wanted into the bigshell file.

Ollie
User avatar
ollie wright
 
Posts: 88
Joined: Wed Sep 03, 2008 7:28 pm

Re: Redirect line of output

Postby Diane Dymesich on Tue Nov 11, 2008 10:10 am

Thanks Mike and Ollie!
I used Mikes answer and was about to try Ollies but I got a message from root saying "system Halt now!"
Guess I'll have to do the rest later!
Diane
Diane Dymesich
 
Posts: 31
Joined: Wed Sep 03, 2008 7:27 pm

Re: Redirect line of output

Postby Marcos Valdebenito on Tue Nov 11, 2008 4:10 pm

Hey Olli
what is "13298 13266" in your command?



I used:
ps -l | grep "13298 13266" | tee bigshell which put the line I wanted into the bigshell file.

Ollie
Marcos Valdebenito
 
Posts: 56
Joined: Wed Sep 03, 2008 7:26 pm

Re: Redirect line of output

Postby Michael Wicherski on Tue Nov 11, 2008 4:20 pm

it would seem that he first did the ps -l command on its own and then grep searched the output to match the filesize of the biggest shell

whereas with mine you need to run ps -l on its own and then count the lines; up to you which is easier to remember
Michael Wicherski
 
Posts: 140
Joined: Mon Sep 01, 2008 5:23 am

Re: Redirect line of output

Postby ollie wright on Tue Nov 11, 2008 4:29 pm

RE: "13298 13266"
That was the combination of the pid and ppid when I first ran ps -l. I ran it (ps -l) just now and got a different combination. These numbers will be different for each person and vary by session. The point is to find something unique on the line you want grep to match. I tried grep using the process size at it also worked. If you just use the ppid, you get the pid's and ppid's linked to the ppid.

Hope this helps - Ollie
User avatar
ollie wright
 
Posts: 88
Joined: Wed Sep 03, 2008 7:28 pm

Re: Redirect line of output

Postby Marcos Valdebenito on Tue Nov 11, 2008 4:39 pm

Hi illi
thanks, it make sense...
Thanks again
Marcos Valdebenito
 
Posts: 56
Joined: Wed Sep 03, 2008 7:26 pm

Re: ps -l | head -2 | tail -n1 > file

Postby ollie wright on Wed Nov 12, 2008 8:03 am

This is a very useful and flexible bit of code. I enjoy looking at code and seeing how someone else solves a problem.

Thanks..
User avatar
ollie wright
 
Posts: 88
Joined: Wed Sep 03, 2008 7:28 pm

Re: Redirect line of output

Postby Rich Simms on Thu Nov 13, 2008 4:01 pm

Both ways work well, another spin on Ollie's would be:

[code]sh-3.2$ ps -l | grep csh > bigfile[/code]

- Rich
User avatar
Rich Simms
Site Admin
 
Posts: 640
Joined: Thu May 15, 2008 2:44 pm

Next

Return to CIS 90 - Fall 2008

Who is online

Users browsing this forum: No registered users and 0 guests

cron