Hi,
I need to
1. read various csv files in a hard-coded folder ( 2 columns)
2. Save the output of columns 1 and column 2 to var1 and var2
3. Copy a template file I have and generate a new file name based on var2.
4. Make substitutions inside the new file for instances of Field1 = (var1) and Field2 = (var2)
For the CSV file:
Column1 has a 4 to 6 digit value
Column2 has names with "\", spaces and "-", but no commas
So far, I have most of the code pseudo-code
#!/bin/bash
FILES=/mydir/*.txt
for f in $FILES
do
echo "Processing $f file..."
var1=$(awk -F ',' ' {print $1}' $f )
var2=$(awk -F ',' ' {print $2}' $f )
echo "Doing $var1 and $var2"
cp /myotherdir/Skeleton-File /myotherdir/"$var2"-"$var1"-newfile
sed -e "s/Field1/"$var1"/g" -i /myotherdir/"$var2"-"$var1"-newfile
sed -e "s/Field2/"$var2"/g" -i /myotherdir/"$var2"-"$var1"-newfile
done
I have had mixed results attempting nested do loops, but my main problem seems to be with var2, attempting $var2, bash treats spaces as a new line (even though awk prints it ok) and "$var2" treats the variable as a single long line and generates a combined file name of all the contents.
Any ideas on how to accomplish this?
Thanks
I need to
1. read various csv files in a hard-coded folder ( 2 columns)
2. Save the output of columns 1 and column 2 to var1 and var2
3. Copy a template file I have and generate a new file name based on var2.
4. Make substitutions inside the new file for instances of Field1 = (var1) and Field2 = (var2)
For the CSV file:
Column1 has a 4 to 6 digit value
Column2 has names with "\", spaces and "-", but no commas
So far, I have most of the code pseudo-code
#!/bin/bash
FILES=/mydir/*.txt
for f in $FILES
do
echo "Processing $f file..."
var1=$(awk -F ',' ' {print $1}' $f )
var2=$(awk -F ',' ' {print $2}' $f )
echo "Doing $var1 and $var2"
cp /myotherdir/Skeleton-File /myotherdir/"$var2"-"$var1"-newfile
sed -e "s/Field1/"$var1"/g" -i /myotherdir/"$var2"-"$var1"-newfile
sed -e "s/Field2/"$var2"/g" -i /myotherdir/"$var2"-"$var1"-newfile
done
I have had mixed results attempting nested do loops, but my main problem seems to be with var2, attempting $var2, bash treats spaces as a new line (even though awk prints it ok) and "$var2" treats the variable as a single long line and generates a combined file name of all the contents.
Any ideas on how to accomplish this?
Thanks