[K12OSN] Scripting help...how to read lines from a text file

Petre Scheie petre at maltzen.net
Tue Oct 4 18:55:46 UTC 2005


If you call the script stopthem, and your text file with the list of names is called 
list.txt, then you call it this way:

./stopthem list.txt

Within the script, $1 is the first command line parameter, in this case, the file you're 
parsing.

David Trask wrote:
> I understad 90%....one question...where do I indicate the filename? 
> Here's what I believe it will look like, but I'm not totally sure where I
> indicate the path to the text file....
> 
> #!/bin/bash
> cat $1 |while read LINE
> do
>    echo "Processing $LINE"
> stop $LINE
> done
> 
> 
> 
> "Support list for opensource software in schools." <k12osn at redhat.com> on
> Tuesday, October 04, 2005 at 11:41 AM +0000 wrote:
> 
>>You want to use the 'read' command:
>>
>>#!/bin/bash
>>cat $1 |while read LINE
>>do
>>  echo "Processing $LINE"
>>done
>>
>>Run the above with your text file and you'll see the result, and then you
>>can add your 
>>stop command to the line after the echo.  HTH
>>
>>Petre
>>
>>
>>David Trask wrote:
>>
>>> Hi,
>>>
>>>I'm trying to write a script to log off kindergarten kids.  TeacherTool
>>>and Fl_TeacherTool will work, but I'd like to make it easier.  Here's
>>
>>what
>>
>>>I'm trying to do....
>>>
>>>I have a script that I call "stop"  (usage is:  stop username) which
>>>simply kills the user and all associated processes...very effective. 
>>
>>What
>>
>>>I'm trying to do is write another script that will read the usernames
>>
>>from
>>
>>>a list in a text file.  
>>>
>>>I know how to get names from /home....
>>>
>>>for x in `ls /home`; do
>>>
>>>But now I need to know how to read each line in a text file that looks
>>>something like:
>>>
>>>mjones
>>>ssmith
>>>jdoe
>>>rhuard
>>>gwelch
>>>
>>>and execute the command against it.....how can I do this?  I want the
>>>script to read each line....execute the stop command and then do the
>>
>>next
>>
>>>line....
>>>
>>>David N. Trask
>>>Technology Teacher/Coordinator
>>>Vassalboro Community School
>>>dtrask at vcsvikings.org
>>>(207)923-3100
>>>
>>>_______________________________________________
>>>K12OSN mailing list
>>>K12OSN at redhat.com
>>>https://www.redhat.com/mailman/listinfo/k12osn
>>>For more info see <http://www.k12os.org>
>>>
>>_______________________________________________
>>K12OSN mailing list
>>K12OSN at redhat.com
>>https://www.redhat.com/mailman/listinfo/k12osn
>>For more info see <http://www.k12os.org>
> 
> 
> 
> 
> David N. Trask
> Technology Teacher/Coordinator
> Vassalboro Community School
> dtrask at vcsvikings.org
> (207)923-3100
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
> 




More information about the K12OSN mailing list