LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-17-2008, 12:24 AM   #1
jianelisj
LQ Newbie
 
Registered: Mar 2008
Posts: 18

Rep: Reputation: 0
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
 
Old 03-17-2008, 12:34 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Is this solution correct?
What happens when you run it?
 
Old 03-17-2008, 02:00 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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.

Last edited by konsolebox; 03-17-2008 at 02:01 AM.
 
Old 03-17-2008, 06:27 AM   #4
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
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.

Last edited by Simon Bridge; 03-17-2008 at 06:35 AM.
 
Old 03-17-2008, 12:27 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by jianelisj View Post
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.
 
  


Reply



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
Bash script for editing contents of one file according to other kkpal Linux - Newbie 8 02-26-2008 03:49 AM
my cd contents file names not displaying morethan 8 digits. AMajeed AIX 5 08-08-2007 09:56 AM
Script that prints AVI file info using mplayer output Marel Programming 1 08-03-2007 08:50 PM
Need help with a script that looks for contents of a file rsmccain Linux - General 5 12-05-2006 04:26 PM
Script to check for contents in a file darin3200 Programming 7 04-25-2004 05:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration