Quote:
Originally Posted by bulgin
However, now I need to:
rather than use $1 to bring in only one entry, I would like to bring in a txt with entries, such as sample-data2.txt
That's where I'm stuck.
(rename bashy.sh.txt to bashy.sh)
|
If I'm interpreting your post correctly (which is questionable given the amount of cold medication I've been downing), what I would do is:
Take everything from "PART1=$(echo "$1" ..." to "done" and turn it into a bash function:
Code:
function parse_record() {
PART1=$(echo "$1" ...
...
done
}
Another assumption: You got that code block doing what you need it to do. (It sounded like that was working OK in your OP.)
Then, at the bottom of your script, use a loop like:
Code:
INPUTFILE=$1
cat $INPUTFILE | while read RECORD
do
if [ -n "${RECORD} ]; then # Process only non-empty records though we could
parse_record "${RECORD}" # get fooled by records with nothing but whitespace.
fi
done
To further tweak the main script to handle multiple files on the command line, wrap the following around the above code block:
Code:
FILELIST=$*
for INPUTFILE in ${FILELIST}
do
if [ -r ${INPUTFILE} ]; then # File exists and we can read it.
<see code block above minus the INPUTFILE=$1 bit>
fi
done
Hoping this gets you close to what you're looking for.
Cheers...