Compare Files

February 5, 2010 at 08:56:49
Specs: Windows XP
Searched about comparing two text files but nothing seem like helping to give me a solution

my text file look like;
A.log
--------
5
asd.edf
ref.pdf
rty.erf
prt.pdf
test.htf

B.log
-------------
3
asd.edf
rty.erf
prt.pdf

i tried to compare with this shell script
file1= /cygdrive/C/A.txt
file2= /cygdrive/C/B.txt

sdiff $file1 $file2 |grep '<'>>/cygdrive/c/C.log

Above script able to show the difference but its creating a new line after for every difference
how to get the differences without getting the line after <

output look like
ref.pdf
<
test.htf
<

how to get the diffrences without creating new line??
guide plzz


See More: Compare Files

Report •


#1
February 5, 2010 at 10:32:25
Weird ... the GREP says to show only lines with <

Isn't this an issue with unix versus DOS line return codes ?
If you CAT the file, does he show it correctly ?


Report •

#2
February 5, 2010 at 12:35:37
sdiff $file1 $file2 |grep '<'>>/cygdrive/c/C.log | tr -d "[\012]"


Report •

#3
February 5, 2010 at 21:31:18
what tr -d "[\012]" do??
i cant really see the differences but stil it giving me the same output


Report •

Related Solutions

#4
February 5, 2010 at 21:56:16
its supposed to TRanslate characters in the io-stream, in this case remove '\n' or newline char.s. (see: man tr for more info), \012 is octal for dec 10 hex 0A. It might be that your system uses 0D (13 dec. 015 octal) or even both. I tested this on telnet connection to Ubuntu, where it worked ok. Newline is almost never anything but 0A (ctrl-J), 0D (ctrl-M) or both together as 0A0D or 0D0A pairs.

@tvc: i didn't comprehend what you meant by line return codes (i misconstrued as return-codes as in errorlevel). so yeah, you're prob'ly right, its issue of line-return-codes as in "newline" and what is being used for them on his system. the apparent non-functioning of "grep" (ie: leaving in the filenames) is prob'ly due to his post wrapping bunches of spaces so it looks like newline.


Report •

#5
February 5, 2010 at 23:23:11
How to check system uses OD or OA?

Report •

#6
February 6, 2010 at 00:14:25
good question. in Windows/Dos-box, you can use EDIT /70 or DEBUG and view files in hexadecimal. I do not know the equivalent functions to use in Unix env. yet, but i'm sure there is one, or more. this is feeble as hell, but one way:
echo A>test
echo B>>test
cat test | tr "[\012\015]" "#_"
and see, if output shows #, the newline is 0A, if output shows _, newline is 0D. Also combinations... #_ or _#

I'm really new at unix scripting, so bear with me. like i said, it's a weak attempt and i know there's better ways. hopefully someone with knowhow will help you.


Report •

#7
February 6, 2010 at 13:11:24
ah!
hd file.txt
(any text file will do), look to see what is between the lines.

Report •

#8
February 7, 2010 at 06:18:23
> @tvc: i didn't comprehend what you meant by line return
> codes (i misconstrued as return-codes as in errorlevel).
> so yeah, you're prob'ly right, its issue of line-return-codes
> as in "newline" and what is being used for them on his
> system. the apparent non-functioning of "grep" (ie: leaving
> in the filenames) is prob'ly due to his post wrapping bunches
> of spaces so it looks like newline.
>

Yeah, I just meant : return, enter, line-return, end-of-line character ... not exit-code or errorlevel

I'm still struggling to name that one correctly ;)


Report •

#9
February 7, 2010 at 06:25:25
> good question. in Windows/Dos-box, you can use
> EDIT /70 or DEBUG and view files in hexadecimal. I
> do not know the equivalent functions to use in Unix
> env.
>

Me neither ... never had the need to hex-view any file on unix, just use VI and you'll have a rough idea. If you look at an incorrectly transferrred (FTP'ed) file from Windows to Unix, it would show lots of control-M characters at the end of each line, in VI

In the case of *nix, it's easy since you have to remove characters, you can just remove them manually, if that ever would be a problem.

Of course, you can TR them, but better is to see why they are transferred incorrectly, and fix that. That would by the way also be my advice in this thread. Messing with these characters is a pain in the ... If some files are transferred incorrectly, I would be worried about other files as well.


Report •

#10
February 8, 2010 at 07:32:58
Doesn't Cygwin have dos2unix? If so, why not just use that?

Report •

Ask Question