I made a simple shell script to unzip and edit a csv file. the code run well on command line but unable to run on bash script. Which part do I need to modify?
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/octave/
read -p "File Date: " fileDate #
filePath="tt_D01_"$fileDate".zip"
csvPath=$fileDate"_01_TR.csv"
unzip -o -j $filePath '*TR.csv'
vi $csvPath -c ':%s/HHI/1' -c ':%s/HSI/2' -c ':%s/MHI/3' -c ':%s/MCH/4' -c ':%s/F/1' -c ':%s/O/2' -c ':wq!'
split -l 1000000 $csvPath
octave --silent --eval "processData('$fileDate')"
Here is the result
bash test.bash
File Date: 201607
filePath: tt_D01_201607.zip
csvPath: 201607_01_TR.csv
.ZIP.or tt_D01_201607.zipen tt_D01_201607.zip
split: cannot open ‘201607_01_TR.csv\r\r’ for reading: No such file or directory
Please advise. Thanks.
\r
almost always indicates MS Windows was involved either w an editor or FileZilla or other ftp client. On your linux machine, usedos2unix myScript
. (if you get weird results from your csv, thendos2unix "$csvPath"
may be required also). Good luck. – shellter