How to compare a dos text and unix text with diff
How to compare a dos text and unix text with diff
am 03.04.2008 18:13:46 von Kevin Qin
Hi,
I ftped some text file from unix server to my Win PC.
I installed cygwin in my PC and want to compare the unix text and dos
text with diff command.
How can I remove the influence by carriage return?
Even same text file, diff will show different result.
I know the options "-b" can remove this. At the same time, the option
will remove all blanks.
However, I also want to compare blank and tab number in two files.
Any comment will be appreciated.
-Kevin
Re: How to compare a dos text and unix text with diff
am 03.04.2008 18:17:47 von Ed Morton
On 4/3/2008 11:13 AM, Kevin Qin wrote:
> Hi,
> I ftped some text file from unix server to my Win PC.
> I installed cygwin in my PC and want to compare the unix text and dos
> text with diff command.
> How can I remove the influence by carriage return?
>
> Even same text file, diff will show different result.
> I know the options "-b" can remove this. At the same time, the option
> will remove all blanks.
>
> However, I also want to compare blank and tab number in two files.
>
> Any comment will be appreciated.
>
> -Kevin
man dos2unix
Ed.
Re: How to compare a dos text and unix text with diff
am 03.04.2008 18:23:55 von Kevin Qin
On Apr 4, 12:17 am, Ed Morton wrote:
> On 4/3/2008 11:13 AM, Kevin Qin wrote:
>
> > Hi,
> > I ftped some text file from unix server to my Win PC.
> > I installed cygwin in my PC and want to compare the unix text and dos
> > text with diff command.
> > How can I remove the influence by carriage return?
>
> > Even same text file, diff will show different result.
> > I know the options "-b" can remove this. At the same time, the option
> > will remove all blanks.
>
> > However, I also want to compare blank and tab number in two files.
>
> > Any comment will be appreciated.
>
> > -Kevin
>
> man dos2unix
>
> Ed.
Thank you for your input.
I know that the command u2d can convert unix text to dos text.
Is there one way that we can compare the two files with diff command
directly?
Re: How to compare a dos text and unix text with diff
am 03.04.2008 18:39:22 von PK
Kevin Qin wrote:
> Hi,
> I ftped some text file from unix server to my Win PC.
> I installed cygwin in my PC and want to compare the unix text and dos
> text with diff command.
> How can I remove the influence by carriage return?
>
> Even same text file, diff will show different result.
> I know the options "-b" can remove this. At the same time, the option
> will remove all blanks.
>
> However, I also want to compare blank and tab number in two files.
>
> Any comment will be appreciated.
This works with bash, but it's not standard and I don't know whether it
works under cygwin at all:
diff <(cat unixfile | unix2dos) dosfile
or
diff unixfile <(cat dosfile | dos2unix)
If you don't have dos2unix or unix2dos, they can be implemented using sed
one-liners:
unix2dos:
sed 's/$/\r/' (GNU sed)
dos2unix:
sed 's/.$//'
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Re: How to compare a dos text and unix text with diff
am 03.04.2008 22:17:27 von Chris Mattern
On 2008-04-03, Kevin Qin wrote:
> On Apr 4, 12:17 am, Ed Morton wrote:
>> On 4/3/2008 11:13 AM, Kevin Qin wrote:
>>
>> > Hi,
>> > I ftped some text file from unix server to my Win PC.
>> > I installed cygwin in my PC and want to compare the unix text and dos
>> > text with diff command.
>> > How can I remove the influence by carriage return?
>>
>> > Even same text file, diff will show different result.
>> > I know the options "-b" can remove this. At the same time, the option
>> > will remove all blanks.
>>
>> > However, I also want to compare blank and tab number in two files.
>>
>> > Any comment will be appreciated.
>>
>> > -Kevin
>>
>> man dos2unix
>>
>> Ed.
>
> Thank you for your input.
> I know that the command u2d can convert unix text to dos text.
> Is there one way that we can compare the two files with diff command
> directly?
If you have GNU dos2unix, you can just use it as part of a pipe:
cat a.txt | dos2unix | diff - b.txt
Note that this doesn't work with less capable dos2unixes, like the
one that comes with Solaris.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
Re: How to compare a dos text and unix text with diff
am 03.04.2008 22:21:01 von Chris Mattern
On 2008-04-03, pk wrote:
> Kevin Qin wrote:
>
>> Hi,
>> I ftped some text file from unix server to my Win PC.
>> I installed cygwin in my PC and want to compare the unix text and dos
>> text with diff command.
>> How can I remove the influence by carriage return?
>>
>> Even same text file, diff will show different result.
>> I know the options "-b" can remove this. At the same time, the option
>> will remove all blanks.
>>
>> However, I also want to compare blank and tab number in two files.
>>
>> Any comment will be appreciated.
>
> This works with bash, but it's not standard and I don't know whether it
> works under cygwin at all:
>
> diff <(cat unixfile | unix2dos) dosfile
>
> or
>
> diff unixfile <(cat dosfile | dos2unix)
>
You don't need to do this; it's not a pure bashism, but older
shells will have trouble with it. However, diff accepts
"-" as a file argument meaning standard input, so you
can use a regular old pipe. However, many dos2unixes
won't write to standard output (bad utility! bad!),
so this may not work if you don't have the GNU
dos2unix.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
Re: How to compare a dos text and unix text with diff
am 04.04.2008 04:07:48 von Maxwell Lol
Kevin Qin writes:
> Hi,
> I ftped some text file from unix server to my Win PC.
I think If you used ascii mode instead of binary mode, this would not
be necessary to convert using unix2dos, etc....
also diff has options to ignore whitespace. Try -w or -b.
Re: How to compare a dos text and unix text with diff
am 04.04.2008 08:55:35 von PK
Chris Mattern wrote:
>> diff unixfile <(cat dosfile | dos2unix)
>>
> You don't need to do this; it's not a pure bashism, but older
> shells will have trouble with it.
Yes, that's why I said it's not standard.
> However, diff accepts "-" as a file argument meaning standard input, so
> you can use a regular old pipe.
Correct. That's a cleaner and more portable solution, thanks.
> However, many dos2unixes won't write to standard output (bad utility!
> bad!),
Yes, it forces a UUOC (which in this case is not useless, of course, but
could be avoided).
> so this may not work if you don't have the GNU dos2unix.
But the sed one-liners may be used instead.
Thanks for your comments!
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.