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…….

 
 

njoy the simplicity…….
©Victimizeit

Advertisements

About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: