I'm writing a simple shell script to make use of dos2unix
command to convert Windows-format files to Unix format as and when it arrives in my folder.
I used to use iconv
in the script and automate it to get one encoding converted to the other. But now I need to use dos2unix
instead of iconv
.
I don't want the original file to be overwritten (it must be archived in the archive
folder). This was straightforward with iconv
; how can I do the same with dos2unix
?
This is my script:
cd /myfolder/storage
filearrival_dir= /myfolder/storage
filearchive_dir=/myfolder/storage/archive
cd $filearrival_dir
echo " $filearrival_dir"
for file in File_October*.txt
do
iconv -f UTF16 -t UTF8 -o "$file.new" "$file" &&
mv -f "$file.new" "$file".`date +"%C%y%m%d"`.txt_conv &&
mv $file $filearchive_dir/$file
done
The above looks for files matching File_Oct*.txt
, converts to the desired encoding and renames it with the timestamp and _conv
at the end. This script also moves the original file to the archive.
How can I replace iconv
in the above script with dos2unix
and have the files archived and do the rest just like I did here?