I have a number of .csv files with tab delimiter and now I want to change the delimiter. When I use the below script it does not change the file. Please help me with the script.
file_mask=$1
from_delim=$2
to_delim=$3
for i in `ls $file_mask*`
do
sed -i 's|$from_delim|$to_delim|g' $i
done
Do not use sed or tr for this, use csvtool (available from common repositories). If you have TABs in strings the above simple tools will choke. You will need to use awk to start counting quotes, etc. It's gonna be a mess with these basic tools.
To replace TABs with e.g. semi-colons with csvtool including all corner cases is simple:
csvtool -t TAB -u ';' cat $ifile -o $ofile
With $ifile the input file and $ofile the output file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With