Convert a group of Dos files to Unix files

Convert a group of Dos files to Unix files

Post by <p.. » Fri, 02 Mar 2001 13:30:04



Greetings,

I have nothing but a bunch of Dos file (xxx.txt) in my directory.  I need
to convert them to Unix files and keep their file names the same(xxx.txt).

Doing "dos2unix xxx.txt xxx.txt" on each one of them is very painful.  Can
you please let me know how to convert them all together with a script?

Thank you very much.  It's a great deal to me.

Ping  

--
Posted via CNET Help.com
http://www.help.com/

 
 
 

Convert a group of Dos files to Unix files

Post by Tony Curti » Fri, 02 Mar 2001 13:35:05


>> On Thu, 01 Mar 2001 04:30:04 -0000,

> Greetings, I have nothing but a bunch of Dos file
> (xxx.txt) in my directory.  I need to convert them to
> Unix files and keep their file names the same(xxx.txt).
> Doing "dos2unix xxx.txt xxx.txt" on each one of them is
> very painful.  Can you please let me know how to convert
> them all together with a script?

Well, that's just what a script does too :-)

Assuming a Bourne-like shell:

    for f in *.txt; do dos2unix $f; done

(I've studiously avoided csh-like shells for yonks, but it
would be "foreach f (*.txt)" something, see the man page
for details.)

hth
t
--
The avalanche has already started.
It is too late for the pebbles to vote.

 
 
 

Convert a group of Dos files to Unix files

Post by R. Schich » Fri, 02 Mar 2001 19:28:36


in "sh" type in the following (from the correct path)
for i in ls
do
  dos2unix $i > $i
done

Be sure you use and not ` :-)

Hope this will help

Kind regards

R. Schicht


> Greetings,

> I have nothing but a bunch of Dos file (xxx.txt) in my directory.  I need
> to convert them to Unix files and keep their file names the same(xxx.txt).

> Doing "dos2unix xxx.txt xxx.txt" on each one of them is very painful.  Can
> you please let me know how to convert them all together with a script?

> Thank you very much.  It's a great deal to me.

> Ping

> --
> Posted via CNET Help.com
> http://www.help.com/

 
 
 

Convert a group of Dos files to Unix files

Post by John Howell » Fri, 02 Mar 2001 19:43:20



> in "sh" type in the following (from the correct path)
> for i in ls
> do
>   dos2unix $i > $i
> done

The calling shell will open the output file for writing before the command is
executed, so this will delete the content from all the files. You would need to
do something like:

for i in `ls`
do
        dos2unix $i > tmp
        mv tmp $i
done

John Howells
Marconi

 
 
 

Convert a group of Dos files to Unix files

Post by Z. Majee » Sat, 03 Mar 2001 02:49:17




> > in "sh" type in the following (from the correct path)
> > for i in ls
> > do
> >   dos2unix $i > $i
> > done

> The calling shell will open the output file for writing before the command
is
> executed, so this will delete the content from all the files. You would
need to
> do something like:

> for i in `ls`
> do
> dos2unix $i > tmp
> mv tmp $i
> done

> John Howells
> Marconi

Well, as it happens dos2unix (and unix2dos) takes input and output file
names,
so redirection is unnecessary.

SYNOPSIS
     dos2unix [ -ascii ]  [ -iso ]  [ -7 ]  originalfile  conver-
     tedfile
DESCRIPTION
     If the original file and the converted file  are  the  same,
     dos2unix will rewrite the original file after converting it.

So the following will work:
$ for file in *.txt; do dos2unix $file $file; done

Zartaj

 
 
 

Convert a group of Dos files to Unix files

Post by Darren Dunha » Sat, 03 Mar 2001 05:07:20



> Greetings,
> I have nothing but a bunch of Dos file (xxx.txt) in my directory.  I need
> to convert them to Unix files and keep their file names the same(xxx.txt).
> Doing "dos2unix xxx.txt xxx.txt" on each one of them is very painful.  Can
> you please let me know how to convert them all together with a script?
> Thank you very much.  It's a great deal to me.

There's also the perl solution.  This converts "in place".

% perl -pi -e 's/\r$//;' *.txt

:-)

--

Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >

 
 
 

Convert a group of Dos files to Unix files

Post by Peter Sundstro » Sat, 03 Mar 2001 11:05:06




> > I have nothing but a bunch of Dos file (xxx.txt) in my directory.  I
need
> > to convert them to Unix files and keep their file names the
same(xxx.txt).

> > Doing "dos2unix xxx.txt xxx.txt" on each one of them is very painful.
Can
> > you please let me know how to convert them all together with a script?

> in "sh" type in the following (from the correct path)
> for i in ls
> do
>   dos2unix $i > $i
> done

> Be sure you use and not ` :-)

UUOLS and incorrect quotes.

for i in *.txt

or if you *really* want

for i in `ls *.txt`

 
 
 

Convert a group of Dos files to Unix files

Post by Ian P. Springe » Tue, 06 Mar 2001 09:02:30


Actually, that doesn't work.  Try it out.





> > > in "sh" type in the following (from the correct path)
> > > for i in ls
> > > do
> > >   dos2unix $i > $i
> > > done

> > The calling shell will open the output file for writing before the command
> is
> > executed, so this will delete the content from all the files. You would
> need to
> > do something like:

> > for i in `ls`
> > do
> > dos2unix $i > tmp
> > mv tmp $i
> > done

> > John Howells
> > Marconi

> Well, as it happens dos2unix (and unix2dos) takes input and output file
> names,
> so redirection is unnecessary.

> SYNOPSIS
>      dos2unix [ -ascii ]  [ -iso ]  [ -7 ]  originalfile  conver-
>      tedfile
> DESCRIPTION
>      If the original file and the converted file  are  the  same,
>      dos2unix will rewrite the original file after converting it.

> So the following will work:
> $ for file in *.txt; do dos2unix $file $file; done

> Zartaj

 
 
 

Convert a group of Dos files to Unix files

Post by Z. Majee » Wed, 07 Mar 2001 10:19:18




Quote:> Actually, that doesn't work.  Try it out.

Is there any reason to take a condescending tone? If it does not work,
explain why not for everyone's benefit. Why be coy?

Anyway it does work. I use it every day developing for both NT and Solaris.
Here's a sample:

chogori> for n in 1 2 3; do echo "\r" > $n.txt; done
chogori> ls -l
total 6
-rw-r--r--   1 owner staff          2 Mar  5 17:12 1.txt
-rw-r--r--   1 owner staff          2 Mar  5 17:12 2.txt
-rw-r--r--   1 owner staff          2 Mar  5 17:12 3.txt
chogori> sed -n l *.txt
\r$
\r$
\r$
chogori> for file in *.txt; do dos2unix $file $file; done
chogori> ls -l
total 6
-rw-r--r--   1 owner staff          1 Mar  5 17:13 1.txt
-rw-r--r--   1 owner staff          1 Mar  5 17:13 2.txt
-rw-r--r--   1 owner staff          1 Mar  5 17:13 3.txt
chogori> sed -n l *.txt
$
$
$
chogori> for file in *.txt; do unix2dos $file $file; done
chogori> ls -l
total 6
-rw-r--r--   1 owner staff          2 Mar  5 17:14 1.txt
-rw-r--r--   1 owner staff          2 Mar  5 17:14 2.txt
-rw-r--r--   1 owner staff          2 Mar  5 17:14 3.txt
chogori> sed -n l *.txt
\r$
\r$
\r$

Zartaj






> > > > in "sh" type in the following (from the correct path)
> > > > for i in ls
> > > > do
> > > >   dos2unix $i > $i
> > > > done

> > > The calling shell will open the output file for writing before the
command
> > is
> > > executed, so this will delete the content from all the files. You
would
> > need to
> > > do something like:

> > > for i in `ls`
> > > do
> > > dos2unix $i > tmp
> > > mv tmp $i
> > > done

> > > John Howells
> > > Marconi

> > Well, as it happens dos2unix (and unix2dos) takes input and output file
> > names,
> > so redirection is unnecessary.

> > SYNOPSIS
> >      dos2unix [ -ascii ]  [ -iso ]  [ -7 ]  originalfile  conver-
> >      tedfile
> > DESCRIPTION
> >      If the original file and the converted file  are  the  same,
> >      dos2unix will rewrite the original file after converting it.

> > So the following will work:
> > $ for file in *.txt; do dos2unix $file $file; done

> > Zartaj

 
 
 

Convert a group of Dos files to Unix files

Post by Griff Mille » Sun, 11 Mar 2001 06:36:06



> Greetings,

> I have nothing but a bunch of Dos file (xxx.txt) in my directory.  I need
> to convert them to Unix files and keep their file names the same(xxx.txt).

> Doing "dos2unix xxx.txt xxx.txt" on each one of them is very painful.  Can
> you please let me know how to convert them all together with a script?

> Thank you very much.  It's a great deal to me.

Create a file like this:

#!/bin/sh

cd /where/the/files/are

for a in *.txt ; do
  dos2unix $a /tmp/$a
  cp /tmp/$a $a
  rm /tmp/$a
done

exit

...

Then just "chmod +x" the file, and run it. Obviously, you'll have to
edit it slightly first, but that should give you the idea.

--
Griff Miller II
Manager of Information Technology      "Beware of those who seek to win an
Positron Corporation                    argument at the expense of the