LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Make a Script Fle that opens A file and prints its contents (processes names) once (https://www.linuxquestions.org/questions/linux-newbie-8/make-a-script-fle-that-opens-a-file-and-prints-its-contents-processes-names-once-628556/)

jianelisj 03-17-2008 12:24 AM

Make a Script Fle that opens A file and prints its contents (processes names) once
 
i want to make a script file that opens a file with name procs (that exists in hom directory) and prints the processes that are written into it (the file procs consists of procceses names each one in a different line. If a process name is written twice then it must be print ony one time)

My solution is:

for i in ./procs
do
echo $i | uniq
done

Is this solution correct? I would aprreciate any help

Simon Bridge 03-17-2008 12:34 AM

Quote:

Is this solution correct?
What happens when you run it?

konsolebox 03-17-2008 02:00 AM

if it's ok to sort the contents of procs, do

Code:

for i in $(sort ./procs | uniq); do
  echo ${i}
done

if not sorting, use temporary variables like:
Code:

for i in $(<./procs); do
  if eval "[ -z \"${temp_${i}}\" ]"; then
    eval temp_${i}=1
    tempvars=${tempvars}\ temp_${i}
    echo "${i}"
  fi
done
unset ${tempvars} tempvars

LOL: looked at all his posts.. this guys looks like a *BOT*!.. anyway i'm just finishing my post since i already started it.

Simon Bridge 03-17-2008 06:27 AM

Hmmm... <goes and looks> heh :\ I see what you mean.
Bots don't normally respond to replies though do they? With such a lot (and about one per day) all around the same somewhat narrow subject (sorting files, or through files, in bash) I could suspect homework here.

<checks harder>
BUSTED!

These are homework questions.

Was previously told that homework help is easier to get if he shows us what he's tried, since then, he's been posting some random code as well.

Tinkster 03-17-2008 12:27 PM

Quote:

Originally Posted by jianelisj (Post 3090933)
i want to make a script file that opens a file with name procs (that exists in hom directory) and prints the processes that are written into it (the file procs consists of procceses names each one in a different line. If a process name is written twice then it must be print ony one time)

My solution is:

for i in ./procs
do
echo $i | uniq
done

Is this solution correct? I would aprreciate any help

You clearly need to start reading your course material.

There's no point in regurgitating stuff for you if you're
not taking anything in.

Do your own homework.


All times are GMT -5. The time now is 01:39 AM.