I faced a very strange problem when I unzip a zip file on my solaris workstation. Actually I wanted to transfer a folder, say it TEST which contains some sub-folders inside it from windows to solaris machine. So I zipped this folder to TEST.ZIP on my windows machine.
Then from my windows machine, I started ftp from command prompt and connected to my solaris machine and I copied this TEST.ZIP folder using put command to my solaris mahcine in bin mode.
On my solaris machine, I extracted this folder by following command :-
$ unzip TEST.ZIP
It unzipped the folder and produced a TEST folder. But the problem is that when I opened any file from any of the sub-folders of this TEST folder using vi editor, in every line it is showing "^M" i.e., control + M character which I dont intended.
Firstly I could not know how these control chars are getting appended. But when I searched on google for solving the problem, I could only find the reason but not its solution. The reason for these control char is that in window every line is terminated by Enter or Return key which in solaris mahcine appeared as these control chars.
The later option does not worked for me showing the error message "Searched pattern match failed". The first option dos2unix is working but its suitable for only some of the files or only few files as for it the source file name and target file name should be different. So I tried to firstly cp/mv all file like this mv *.cc *.cc.old
or cp *.cc *.cc.old
which failed because the cp or mv command failed for * wildcard. I cant manually change for each file as I am having a bunch of files.
Sorry to say that even this doesnt work. Also when I also tried to find out
only ^M in file by typing /^M enter; then that too didnt worked out.
The reason is that it pertains combination of the two chars ^ and M as a single char and not two different chars. I came to known this conclusion by deleting the char ( using x key in escape mode). It needs to press only one time the x key for deleting this combination of these two chars.
The ^M that you are talking about here are not two characters. Its actually a control character. Use 'ctrl-V ctrl-M' to get the actual character. Try this in vi:
Thanks. It worked for me. I really appreciate your efforts and heartly thankful to you for solving my problem and also to unix.com forums. It really works.
One more thing at last, by this way I need to open all the files which may be in same sub-folders for changing all files. IS there any way to operate it or dos2unix command for all files in the same folder and in sub-folders in
one command action.
thanks neeraj,
but sorry to say that the later option of using find command is not working. And moreover the problem with first option is that I need to dos2unix each file . I mean I cant change all files of even same type by using following command:-
dos2unix -ascii -43 *.cc
Although dos2unix -ascii -43 test1.cc test1.cc is working.
Any other details in this regard which may prove helpful to me?
Thanks to all of you who have take your time again. I got my problem solved in the way I was looking for, i.e., a single command worked for me which did the dos/window to unix format transformation in a single command for all the files in a folder and sub-folders.
It is find . -type f -print | xargs -I {} dos2unix -ascii {} {}