Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-17-2008, 04:26 AM   #1
LQ Newbie
Registered: Mar 2008
Posts: 18

Rep: Reputation: 0
Distinguish from the contents of a file which are the processes and print them

I have a file with name procs and the following content:


how can i recognize which of these names are processes names and print only them

My solution is

for i in procs
if [ -p $i]
echo $i

but is does not work. I would appreciate any help.
Old 03-17-2008, 05:27 AM   #2
Registered: Apr 2007
Location: Adelaide, Australia
Distribution: Ubuntu 8.10 and 7.10 server
Posts: 95

Rep: Reputation: 15
Try using grep (man grep on how to use) for searching the file.

I use the following from the command line to find a set of characters in a file:
$ cat <filename> | grep ps
Old 03-17-2008, 10:05 AM   #3
LQ Newbie
Registered: Feb 2008
Posts: 4

Rep: Reputation: 0
Something line:

for i in $( cat procs)
if ps -C $i > /dev/null
echo $i
Old 03-17-2008, 01:29 PM   #4
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Originally Posted by jianelisj View Post
I have a file with name procs and the following content:


how can i recognize which of these names are processes names and print only them

My solution is

for i in procs
if [ -p $i]
echo $i

but is does not work. I would appreciate any help.

Why do you consider this a solution? What do you think should
be happening, what do the man-pages for the programs involved
in your "solution" suggest they do, what is the outcome of your

Do your own homework.
Old 03-19-2008, 10:24 AM   #5
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
"It's the syntax, stupid!"

Seriously, tell me the 3 CLI ways to get documentation on a command, & I will tell you which one to use to solve your problem.

Welcome to LQ

Welcome to LQ. Yes, I mean it. I know others have been pretty harsh on you for posting your homework, but in the process they have provided much amusement for the rest us: Find all threads started by jianelisj

Thank you for the wonderful light start to my day.

Proves the old adage: "No one is completely worthless -- you can always be used as a horrible example.

For the moment, you are the horrible example; however, in amongst negative commentary are the seeds of reform -- re-read & learn.

Surprisingly, one thing no one has suggested is Raymond & Moen's "How To Ask Questions the Smart Way" found here or here. (Both of the authors maintain public copies.)

Finally, if you would really like to become a valued, contributing member of LQ, consider the following voluntary homework assignment:
  1. Find the LQ Rules.
  2. Paste them into an editor.
  3. Annotate each original paragraph with an explanation, in your own words, of what it means. The point is to clearly demonstrate that you understand.
  4. Clearly mark the added material.
  5. Make yourself an LQ blog.
  6. Post this assignment there, consisting of:
    1. This list.
    2. The steps to accomplish each one.
    3. The resulting Annotated Rules.
  7. Scoring will based primarily on demonstrating that you understood what you read.
  8. Grammer & spelling count.
  9. Extra points for eloquence.

Last edited by archtoad6; 03-19-2008 at 10:26 AM. Reason: unfinished, posted accidently


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
Make a Script Fle that opens A file and prints its contents (processes names) once jianelisj Linux - Newbie 4 03-17-2008 01:27 PM
[SOLVED] how to distinguish between a original file and a hard link bzlaskar Linux - Newbie 2 12-11-2007 09:58 AM
Bash remove part of a file based on contents of another file bhepdogg Programming 4 01-31-2007 04:13 PM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 05:15 PM
how to distinguish a file and a directory joeyBig Programming 2 10-01-2004 05:21 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:05 PM.

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