Modifying \n\r on a directory tree of html files to \n files for UNIX 
Author Message
 Modifying \n\r on a directory tree of html files to \n files for UNIX

: I am trying to figure out how to change an entire directory of html files
: which have the \r\n line termination to the unix style with just a \n. I
: looked at dejanews and I found this simple one line by Mr. McClellan to
: change a single file named joe.pl.


: You can do that with a perl one-liner too:

: perl -pi.bak -e 's/\r//' joe.pl

: (joe.pl.bak will hold the original (DOS) contents)

: How can I make this so it traverses down a directory tree and modifies
: all .html files? I could not find a recursive switch in the Camel book.

use the File::Find module.

: It seems that having the -i.bak switch is a good idea, but how would I
: get rid of the .bak files once I determine the perl command routine was a
: success?

use the File::Find module  ;-)

along with unlink()

[ if you do:  perl -pi -e ...      then it won't save the original
                     ^
                     ^
  Danger Will Robinson!
]

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Sat, 08 Jul 2000 03:00:00 GMT  
 Modifying \n\r on a directory tree of html files to \n files for UNIX

: I am trying to figure out how to change an entire directory of html files
: which have the \r\n line termination to the unix style with just a \n. I
: looked at dejanews and I found this simple one line by Mr. McClellan to
: change a single file named joe.pl.


: You can do that with a perl one-liner too:

: perl -pi.bak -e 's/\r//' joe.pl

Uhhh. I should have said this instead, because it's faster:

   perl -pi.bak -e 'tr/\r//d' joe.pl

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Sat, 08 Jul 2000 03:00:00 GMT  
 Modifying \n\r on a directory tree of html files to \n files for UNIX


Quote:
>I am trying to figure out how to change an entire directory of html files
>which have the \r\n line termination to the unix style with just a \n. I
>looked at dejanews and I found this simple one line by Mr. McClellan to
>change a single file named joe.pl.

Just a small solution that I use in my scripts to turn dos-linefeeds to
unix line-feeds (when processing said files on the UNIX system).

$file="{path}/file.html"

system "unix2dos -ascii '$file' > tempoutfile.$$ 2>/dev/null";
system "mv $tempoutfile.$$ $file";

The other way:

system "dos2unix -ascii '$file' > tempoutfile.$$ 2>/dev/null";
system "mv $tempoutfile.$$ $file";

It's just an idea that might work for you.

--
Tibbi Scott (Standard Disclaimer: my views are my own.)



Sun, 09 Jul 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Modifying \n\r on a directory tree of html files to \n files for UNIX

2. Modifying all files in a directory tree?

3. Needed: Script for file tree delete and file tree move

4. count lines in files in a directory tree

5. Change Last Modified for all files in a directory

6. ftp changed files in a directory tree?

7. Checking files in a directory tree

8. Problem preserving UID/GID info using File::Path in creating directory tree

9. ANNOUNCE: lntree - Link files in directory trees

10. perform operations on files withing directory tree

11. converting file names down a directory tree

12. WinNT: getting File Last Modified data from outside current directory

 

 
Powered by phpBB® Forum Software