Pure BASH to remove spaces line by line
Submitted by admin on
Here is a neat little script I wrote to remove spaces in CSVs recursively line by line using only pure Bash
#!/bin/bash
INPUT_CSV="test.csv"
INPUT_CSV="test.csv"
set IFS=,
set oldIFS = $IFS
readarray -t arry < ${INPUT_CSV}
for i in "${arry[@]}"
do
:
res="${i//[^ ]}"
cnt="${#res}"
while [ ${cnt} -gt 0 ]; do
i=${i/, /,}
cnt=$[$cnt-1]
done
echo $i
done
If test.csv contains the following entries:
Bob, Jane, Naz, Sue, Max, Tom$
Zero, Alpha, Beta, Gama, Delta, Foxtrot#
Zero, Alpha, Beta, Gama, Delta, Foxtrot#
Then the script will output:
Bob,Jane,Naz,Sue,Max,Tom$
Zero,Alpha,Beta,Gama,Delta,Foxtrot#
Zero,Alpha,Beta,Gama,Delta,Foxtrot#
Add new comment