zuze11 |
11-17-2011 03:12 PM |
reading lines from file
Hi, trying to read data from a file with several blocks in it. Each block corresponds to a particular day and blocks are separated by empty lines. I managed to write a small and very simple bash script that selects the relevant lines and outputs them to separate files for each day.
Here is the script:
Code:
#! /bin/bash
DESCRIPTION='Date Time Ref avgU10 gstU10 dirU10 tC10 RH10 avgU4 avgU2 avgU1 tC0_5 avgU0_5 gstU0_5'
while read LINE
do
FILEID=${LINE:0:6}
if [ ${LINE:0:1} == 9 ]; then
if [ ! -f ${FILEID}.txt ]; then # if file does not exist, add description header
echo ${DESCRIPTION} >> ${FILEID}.txt
echo ${LINE} >> ${FILEID}.txt
else
echo ${LINE} >> ${FILEID}.txt
fi
fi
done
It works simply by redirecting the data file into the script:
./script < datafile
I would like to modify it so I can specify the name of the data file to be processed within the script. Tried a bunch of different things I found on the net but nothing worked. Anybody knows a good way of doing it?
Thanks
|