windows to unix text in subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting windows to unix text in subdirectories
# 1  
Old 12-13-2004
windows to unix text in subdirectories

Hey,

I'm trying to install a java web archive on unix but all the jsp's are in windows text format. I need to convert them all to unix text at once but I really don't want to do that on a file per file basis so I need to loop over all text files in all subdirectories and change the ^M. Does anyone how to do that? I'm new to unix shell scripting and I can't get it to work myself.

Thankx.
# 2  
Old 12-13-2004
There are a few ways to do this. Probably the easiest is with the dos2unix command (dos2ux on some systems)

so...

Code:
for file in /my/path/*
do
  dos2unix $file
done

You could also do it using tr

Code:
for file in /my/path/*
do
  tr -d '\r' < $file > $file.new
  mv $file.new $file
done

Cheers
ZB
# 3  
Old 12-13-2004
more then one level deep?

I changed it to:

#!/usr/bin/ksh
for file in /opt/hpws/tomcat/webapps/jcvsweb/*
do
if [[ -f $file ]]
then
tr -d '\r' < $file > $file.new
mv $file.new $file
fi
done

to make sure it only processes text files and not directories and binaries, which it seemd to do. It only goes one level deep. Is it possible to process all files in all subdirectories?
# 4  
Old 12-13-2004
find /path/to/files -type f -exec dos2unix {} \;
-or-
Code:
find /path/to/files -type f -print | while read file
do
  # add further type testing here
  echo "Converting $file"
  tr -d '\r' < $file > $file.new
  mv $file.new $file
done

This is untested but should work

Cheers
ZB
# 5  
Old 12-13-2004
that works!

perfect! this works just fine.

thanx.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX command to display Owner,Group,Root and Subdirectories list

Hi Team, Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path. I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this . Here is the sample result... (6 Replies)
Discussion started by: vasuvv
6 Replies

2. UNIX for Dummies Questions & Answers

UNIX - command to count number of files in subdirectories

I have a folder named test/ and under that I have multiple directories and in each of the directory I have multiple log files. I want to know how many files exists under each sub directory. test |--quanrantine |--logfile1 |--logfile2 |--spooling |--logfile1 ... (4 Replies)
Discussion started by: ravikirankethe
4 Replies

3. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

4. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

5. UNIX for Dummies Questions & Answers

show all text files in directories and subdirectories

Hi! I am trying to find all text files in my home directory that contain the string "C-d" so I tyied this : cd ~ find . -type f -exec grep -l "C-d" {} + but it took very long so I tryed this : ls -aR | xargs file |grep text but it didn't descend in the directories and it said :... (3 Replies)
Discussion started by: kelamahim
3 Replies

6. UNIX for Dummies Questions & Answers

Send Text message from unix to windows

Hi Buddies, I have a unix client and want to send a message (containg some data) to a windows Database server to query from it and return the result. I shall be so thankfull if you help me out.:b::) Warm Regards, Jessi (1 Reply)
Discussion started by: jessica-adams
1 Replies

7. Shell Programming and Scripting

FTP some text files from Windows box to unix

hi all, can anybody help me with script or command to ftp some text file from windows machine to AIX machine. this is shud be done by executing a shell script. (1 Reply)
Discussion started by: suprithhr
1 Replies

8. Windows & DOS: Issues & Discussions

DOS/Windows CR to a UNIX LF 17 MB text file

Hello, I am on a WinXP home machine with a 17 MB text file and I need to change the DOS/Windows CR to a UNIX LF. Does anyone know how I can do this or even better a WinXP program that can do this for me ? My hobby is my Family History. I know very little about all this type stuff and I... (9 Replies)
Discussion started by: tex
9 Replies

9. Shell Programming and Scripting

how to remove ^M from windows text file in unix

Hi, Need help on windows text file that i get in unix server and need to change and resend for process. Now there is a ^M will be placed for each line of that file i need that to be removed . Someone please help me. Thanks in advance for all help. (1 Reply)
Discussion started by: pragy1999
1 Replies

10. UNIX for Dummies Questions & Answers

Converting Unix text to windows

I am trying to FTP a text file from a machine running LynxOS and I am having problems with the way windows "sees" the characters. For example this is how windows presents the text:     DevProcRcpClass The boxes are what I am having problems with. When viewing the same file on a... (3 Replies)
Discussion started by: mchristisen
3 Replies
Login or Register to Ask a Question