I'm having some trouble getting this code to work, and I have no idea why it's not, Maybe one of you gurus can lend me a hand.
To begin with I have two CSV files structured as such:
Book1.csv:
Desc,asset,asset name,something,waiver,waiver name,init date,wrong date,blah,blah,target
akdhfa,2014,adskf,kadsfjh,123-4567,none,none,none,none,none,BOOP
Book2.csv
Desc,asset,asset name,something,waiver,waiver name,init date,wrong date,blah,blah,target
akdhfa,2014,adskf,kadsfjh,123-4567,none,none,none,none,none
(Lack of "BOOP" on the second book)
What I want is to scan Book1.csv for column 11. If it's there, find the matching row in Book2.csv based on asset and waiver. Then simply append the target to that line.
Here's what I've tried so far:
#!/bin/bash
oldIFS=IFS
IFS=$'\n'
HOME=($(cat Book1.csv))
for i in "${HOME[@]}"
do
target=`echo $i | cut -d "," -f 11`
asset=`echo $i | cut -d "," -f 2`
waiv=`echo $i | cut -d "," -f 5`
if [ "$target" != "target" ]
then
sed -i '/*${asset}*${waiv}*/s/$/,${target}/' Book2.csv
fi
done
IFS=oldIFS
Everything seems to be working except for the sed command. Any suggestions?
*ś be.*'s?