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

Petre Scheie petre at maltzen.net
Tue Oct 4 15:41:01 UTC 2005


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




More information about the K12OSN mailing list