[Techtalk] line by line in bash

Conor Daly conor.daly at oceanfree.net
Mon Jun 9 07:39:46 EST 2003


On Sun, Jun 08, 2003 at 09:23:41PM +0200 or so it is rumoured hereabouts, 
Hamster thought:
> Hi!
> 
> I'm trying to achieve something in bash and not having much luck. Hoping
> some one might know the answer!!
> 
> In essence it boils down to the ability to process a file one line at a
> time.
> 
> I have an existing bash script called "input", a portion of which contains
> the entries:
> 
> # filename input
> 
> export int=blue
> touch $file1
> touch $file2
> touch $file3
> 
> #####
> 
> 
> I am trying to write a second file that performs the following tasks:
> 
> For each line in "input" do 
> 	1. if the first word of the line is export, then execute that line
> 	2. if the first word is touch, then replace the word touch with rm
> 	and then execute that new command.
> 	3. if the line doesnt meet conditions 1 or 2 then just ignore it.

The crucial bit is getting the "input" file in.  A normal "script < input"
may work but I'm not sure.  This works though:

####################
exec < input

read LINE

while [ $LINE ]; do

FISRTWORD=`arbitrary combo of sed and stuff to identify line`
:
:
:

read LINE
done
####################

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
  7:37am  up 25 days, 10:05,  0 users,  load average: 0.01, 0.01, 0.00
Hobbiton.cod.ie
  7:35am  up 25 days, 10:04,  1 user,  load average: 0.04, 0.02, 0.00


More information about the Techtalk mailing list