Read File in bash and split string into variables

Here my requirement is:
1) I have to read my file line by line.
2) For each line read I need to divide my string into two parts
3) Send the two parts formed to some another script for process.

# Here we will read the file and process.
# anjFileName contents are as below
# 2011-10-01 2011-12-31
# 2011-07-01 2011-09-30
# 2011-04-01 2011-06-30
# 2011-01-01 2011-03-31

# It will read lockFileName line by line and store the content into dateRange variable.
# It will separate out the range based on space by using ‘-d’ .
# also instead of space if we have another delimiter say : then -d : -f1 and -f2 gives respective two parts of my string.


for dateRange in `cat ${lockFileName}`
    fromDate=`echo $dateRange| cut -d, -f1` 
    toDate=`echo $dateRange| cut -d, -f2`
    /home/anj/dev/php/bin/php /home/ashu/work/ashu.php ${fromDate} ${toDate}
    sleep 1m

Leave a Reply

Your email address will not be published. Required fields are marked *.

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>