ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a series of Stata scripts (.do-files) that were saved in Windows and I just converted to Linux; Stata interprets the scripts just fine, however when I look at them in a text editor, I get "^M" at the end of every line. This hampers the use of ESS' syntax highlighting. So, I want to accomplish a couple of things, mainly get these files into readable format.
The files are arranged in a subdirectories of two separate directories, themselves subdirectories of /home/joel
1. Go through each file and change "c:/" to "~" and in general change Windows pathnames to UNIX pathnames.
2. fromdos <old-do-file> new-do-file
3. pack up the old-do-files into a tree structure just like the current one and tar-then-bzip2 it so that I only have the new ones in my directories.
The last step seems like the easiest part. I thought of using sed to accomplish goal #1, and fromdos (slackware) is pretty easy to use and always does the job correctly.
HOWEVER, because of the directory structure, I need to do this recursively. Where do I start writing a script that will recursively search for the files I need to edit and change, and archive?
Also, I've been learning and using bash quite a lot -- would it be better to use some other shell (e.g., zsh) to interpret this script?
Stata interprets the scripts just fine, however when I look at them in a text editor, I get "^M" at the end of every line. This hampers the use of ESS' syntax highlighting.
A method to remove the ^M and any other control character is by means of the col command, e.g.
Sounds to me like the files are simply in DOS text format (ie with CR/LF at the end of each line). You say you converted them to Linux, but did you run dos2unix on each file? This will remove the extra control characters automatically.
[QUOTE=Nick_Battle]> Where do I start writing a script that will recursively search
> for the files I need to edit and change, and archive?
Does find(1) not give you what you want?
/QUOTE]
I suppose it does: I just tried it and it prints full pathnames on STDOUT. So, I'll just pipe them from find into whatever command I use to do the editing.
Sounds to me like the files are simply in DOS text format (ie with CR/LF at the end of each line). You say you converted them to Linux, but did you run dos2unix on each file? This will remove the extra control characters automatically.
I said I will convert them using fromdos. fromdos is the Slackware version of dos2unix.
Quote:
Originally Posted by billymayday
How many subdirectories are you talking about?
I'm talking about subdirectories of subdirectories, dude. Recursion to the max.
Seriously, I organize my projects by researchers I work for, then the projects that they are doing, then sometimes by section of the analysis I'm doing.
Thanks for the help -- I think I'm getting a good place to start.
The sed command does exactly what it should, and the find command finds the files just perfectly. My question is how to I redirect the output so that it actually edits the files (saves the STDOUT to the file that I am editing). Right now it will print out the modified out put, and testing the commands individually shows that they are doing what I want, but the actual files are untouched.
The command executes and I get no errors. I also get the files remaining the same, even though I thought I could direct the output back to the file with {} > {}. If I do the above with grep
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.