0

I'm writing a script which converts special characters to text.

How can I arrange it so my script takes a csv file as input and executes sed commands on it?

FILENAME= ls -ltr| grep *.csv

sed -i 's/\xc3\x83/A/g' FILENAME #Ã <br>
sed -i 's/\xc3\x80/A/g' FILENAME #À<br>
sed -i 's/\xc3\x81/A/g' FILENAME #Á<br>
sed -i 's/\xc3\x82/A/g' FILENAME #Â<br>
sed -i 's/\xc3\x85/A/g' FILENAME #Å<br>
Jotne
  • 40,548
  • 12
  • 51
  • 55
Sandeep Johal
  • 399
  • 2
  • 6
  • 16
  • What if you do `for file in *csv`? – fedorqui Nov 21 '14 at 12:23
  • possible duplicate of [Bash: Convert non-ASCII characters to ASCII](http://stackoverflow.com/questions/1975057/bash-convert-non-ascii-characters-to-ascii) – anishsane Nov 21 '14 at 13:05
  • Copied the logic from http://stackoverflow.com/a/1975093/793796 : `for file in *.csv; do iconv -f utf-8 -t ascii//translit < "$file" > "$file.ascii" && mv "$file.ascii" "$file"; done` – anishsane Nov 21 '14 at 13:09

1 Answers1

0

You can simplify the sed command as

sed -i 's/\xc3\x8[0-5]/A/g' FILENAME

To iterate through all the csv files in a directory and apply the sed

for FILENAME in *.csv
do
 sed -i 's/\xc3\x8[0-5]/A/g' $FILENAME
done
nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52