We have moved to www.dataGenX.net, Keep Learning with us.

Thursday, January 05, 2012

dos2nix and nix2dos script : file conversion from unix to/from dos

Hi Guys, Here I am sharing 2 small script which you can use to convert files format after transferring the files from unix to dos or vice versa. This extra carriage return can be removed or inserted with two simple scripts,
you can create 2 executable script files from these code and njoy the nix :-)

There is 2 commands are already there "unix2dos" and "dos2unix" but all shells are not
supporting them. ( see here ) So here it is : ....


dos2nix -- download
# dos2nix
# removes an extra carriage return in a dos/widows
# text file so that end of line matches
# the Unix convention.
# Also removes a control-Z at end of file
# working same as dos2unix command


display()
{
echo "usage: crlf2lf dos.txt unix.txt
exit
}

if [ $# != 2 ]
then
display 
fi

sed 's/^M//g
s/^Z//g' <$1 >$2


nix2dos -- download
# nix2dos
# adds an extra carriage return in a unix
# text file so that end of line matches
# the Windows/DOS convention
# working same as unix2dos command


display()
{
echo "usage: nix2dos nix.txt dos.txt"
exit
}

if [ $# != 2 ]
then
display
fi

sed 's/$/^M/g' <$1 >$2


njoy the simplicity.......

No comments :

Post a Comment