LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Distinguish from the contents of a file which are the processes and print them (https://www.linuxquestions.org/questions/linux-newbie-8/distinguish-from-the-contents-of-a-file-which-are-the-processes-and-print-them-628589/)

jianelisj 03-17-2008 03:26 AM

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:

date
httpd
ps
tty
.....

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

My solution is

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

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

mechdave 03-17-2008 04:27 AM

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

tomrosenfeld 03-17-2008 09:05 AM

Something line:

for i in $( cat procs)
do
if ps -C $i > /dev/null
echo $i
done

Tinkster 03-17-2008 12:29 PM

Quote:

Originally Posted by jianelisj (Post 3091056)
I have a file with name procs and the following content:

date
httpd
ps
tty
.....

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

My solution is

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

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
attempt?


Do your own homework.

archtoad6 03-19-2008 09:24 AM

"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.


All times are GMT -5. The time now is 12:08 PM.