LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-07-2003, 06:35 AM   #1
BongFish
Member
 
Registered: Jun 2003
Location: England
Distribution: Slack 9
Posts: 141

Rep: Reputation: 15
sed....


I need to be able to turn the greped output of 'ps -e' into a list of PID's.

ie.

2073 ? 00:00:00:00 xmms
2074 ? 00:00:00:00 xmms
2075 ? 00:00:00:00 xmms
2076 ? 00:00:00:00 xmms

into

2073 2074 2075 2076



I've read the man and info pages of sed several times as well as the tutorial on the rute pages but I can't work out how to do it!


The only thing I've manages to do is get sed to recognise the actual PID's using /([0-9][0-9][0-9][0-9]/) however I can't do the rest.

Can any sed expert give me a hand?

Cheers
 
Old 08-07-2003, 06:39 AM   #2
mnain
LQ Newbie
 
Registered: Feb 2002
Location: Maryland, USA
Distribution: Mandrake 8.1
Posts: 8

Rep: Reputation: 0
Why do you need all the pid's in one line ?

I suggest you use awk in the following manner

ps -e | grep xmms | awk '{print $1}'

Hope this helps.
Madan
 
Old 08-07-2003, 06:47 AM   #3
BongFish
Member
 
Registered: Jun 2003
Location: England
Distribution: Slack 9
Posts: 141

Original Poster
Rep: Reputation: 15
In a line so I can create a varyable that can be placed after a kill command to kill the apps.


I'm making a script that will automaticaly kill and restart any program if it stops responding.


I'll try your suggestion then get back to you.
 
Old 08-07-2003, 07:31 AM   #4
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
pkill xmms

Or you could go the old way:
kill `ps -ef | grep xmms | awk '{print $2}'`

Last edited by stickman; 08-07-2003 at 07:33 AM.
 
Old 08-07-2003, 09:24 AM   #5
BongFish
Member
 
Registered: Jun 2003
Location: England
Distribution: Slack 9
Posts: 141

Original Poster
Rep: Reputation: 15
The awk thing works perfectly.

I need the PID's in a var for other reasons too so the pkill thing, although good, isn't what I'm looking for.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Sed q? ky-lab_rat Linux - Software 5 10-26-2004 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Help with sed odious1 Linux - General 2 08-29-2003 10:52 AM
help with sed DavidPhillips Programming 3 08-11-2003 04:46 PM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration