UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2008-01-22 05:59 AM

Raj Kumar Arora
Member
Registered: 2008-01-03
Posts: 7

Re: strange problem regarding zip/unzip from window to solaris machine

Hi ,

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.

Anybody who have any idea, please help me ASAP.

Regards,
Raj Kumar Arora

Offline

#2 2008-01-22 06:11 AM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: strange problem regarding zip/unzip from window to solaris machine

Hi Raj,

That problem bites me occasionally as well; it's very annoying.  IIRC what you can do to fix it is a global search-and-replace in vi that replaces every instance of ^M with a proper carriage return.  To do that, load the file into vi and then type something like:

:%s/^M/^M/g

But note that each of the ^Ms in the example above was generated by pressing control-V, then pressing Return... NOT by pressing (shift-6, M)!

Let me know if that doesn't work; I don't have any windows-text files right now to test on so the above is from memory.  If it doesn't work, you might also try

:%s/^M//g

Jeremy

Raj Kumar Arora;23494 wrote:

Hi ,

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.

Anybody who have any idea, please help me ASAP.

Regards,
Raj Kumar Arora

Offline

#3 2008-01-22 06:59 AM

Raj Kumar Arora
Member
Registered: 2008-01-03
Posts: 7

Re: strange problem regarding zip/unzip from window to solaris machine

Sorry my bad luck prevented it from working at my side. The following error message is occurring "SUBSTITUTION PATTERN MATCH FAILED" or "Pattern not found".

Any other option ?

Offline

#4 2008-01-22 07:27 AM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: strange problem regarding zip/unzip from window to solaris machine

Well... according to http://www.vim.org/htmldoc/usr_23.html :

CONVERSION

You can use the 'fileformat' option to convert from one file format to
another.  Suppose, for example, that you have an MS-DOS file named README.TXT
that you want to convert to UNIX format.  Start by editing the MS-DOS format
file:
	vim README.TXT

Vim will recognize this as a dos format file.  Now change the file format to
UNIX:

	:set fileformat=unix
	:write

The file is written in Unix format.


Raj Kumar Arora;23496 wrote:

Sorry my bad luck prevented it from working at my side. The following error message is occurring "SUBSTITUTION PATTERN MATCH FAILED" or "Pattern not found".

Any other option ?

Offline

#5 2008-01-22 08:18 AM

Raj Kumar Arora
Member
Registered: 2008-01-03
Posts: 7

Re: strange problem regarding zip/unzip from window to solaris machine

jfriesne;23497 wrote:

Well... according to

    :set fileformat=unix
    :write

The file is written in Unix format.
[/code]

Sorry it too failed showing following error message
fileformat:No such option.

May be due to the difference between vi and vim, I am using vi editor.

Regards,
Raj Kumar Arora

Offline

#6 2008-01-22 12:58 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,826
Website

Re: strange problem regarding zip/unzip from window to solaris machine

Yes, the ^M is CR...  On DOS/Windoze, the EOL is CR+LF, whereas on Unix, it's
just LF, so that's why you see stray CRs...

Your system might have a conversion script available, such as "dos2unix", which
can do the conversion...  Or, you can just do this:

tr -d '\r' < file > newfile

Offline

#7 2008-01-23 06:08 AM

Raj Kumar Arora
Member
Registered: 2008-01-03
Posts: 7

Re: strange problem regarding zip/unzip from window to solaris machine

RobSeace;23509 wrote:

Yes, the ^M is CR...  On DOS/Windoze, the EOL is CR+LF, whereas on Unix, it's
just LF, so that's why you see stray CRs...

Your system might have a conversion script available, such as "dos2unix", which
can do the conversion...  Or, you can just do this:

tr -d '\r' < file > newfile

Thanks for your time. 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.

Any alternative ?

Regards,
Raj Kumar Arora

Offline

#8 2008-01-23 11:24 AM

Raj Kumar Arora
Member
Registered: 2008-01-03
Posts: 7

Re: strange problem regarding zip/unzip from window to solaris machine

Raj Kumar Arora;23512 wrote:

Thanks for your time. 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.

Any alternative ?

Regards,
Raj Kumar Arora

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 {} {}

Cheers !!!!

Regards,
Raj Kumar Arora

Offline

#9 2008-01-23 01:59 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,230

Re: strange problem regarding zip/unzip from window to solaris machine

A bit late perhaps, but unzip itself probably has an option to do the file conversion automatically if needed (the version I'm using has the "-a" option which does it).

Offline

#10 2009-01-27 08:35 AM

Seo Services
Guest

Re: strange problem regarding zip/unzip from window to solaris machine

Great stuff. I learn new thing from your question. Thanks.

Board footer

Powered by FluxBB