Results 1 to 4 of 4
I'm completely new to scripting and I'm trying to figure out how to write a script that will get a list of all the files in a directory, drilling down ...
- 05-29-2010 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 14
Batch Process files in VI
I'm completely new to scripting and I'm trying to figure out how to write a script that will get a list of all the files in a directory, drilling down through any subdirectories. When I have the list I want to open each file in VI and change the fileformat. So far all I have been able to figure out is that VI can do the batch processing and that "ls -R" gets me the recursive file list. I'm still pretty clueless on how to do the batch process with the VI editor. I think I'm supposed to use the Ex mode but I don't know how to get the list of arguments from the filelist into the editor so they can be processed.
If it matters the files were all written in a Windows editor and have gotten the MS carriage returns so I want to do a :set ff=unix command on all the files without having to go into each file manually, there are over 300 files that need updated.
Thanks for any advice.
- 05-29-2010 #2
If all you want to do is change the carriage return, then sed is your friend.
Code:# Unix2DOS: sed 's/$/\r/' UNIX_file > DOS_file # DOS2Unix sed 's/^M//' DOS_file > UNIX_file
Code:# Or run it 'in place' sed -i 's/^M//' file
And with find /path -exec $command '{}' \;
you can look through the directories and recursively convert all files in one go. Be sure to read the 'find' man page though.Can't tell an OS by it's GUI
- 05-29-2010 #3
Your distro might have a dos2unix convertor already anyway. Try apropos to see if such a command exists, or installing it from your package manager.
- 05-30-2010 #4Just Joined!
- Join Date
- Dec 2007
- Posts
- 14
Thanks guys. I'm unable to use my linux box for a few days but I'll try sed when I get home.


Reply With Quote