Q: Compare lines of files 
Author Message
 Q: Compare lines of files

Hi!

I have the following AWK program:
---------------------------------------------- d.awk ----
BEGIN{
  print "aaaa==aaaa", ("aaaa"=="aaaa")
  print "aaaa< bbbb", ("aaaa"<"bbbb")
  print "bbbb< aaaa", ("bbbb" < "aaaa")
  print

  file1 = ARGV[1]
  file2 = ARGV[2]
  next1 = (getline str1 < file1)
  next2 = (getline str2 < file2)
  while (next1 && next2) {
    print str1 "=" str2 " =" (str1==srt2)
    print str1 "<" str2 " =" (str1<srt2)
    print str1 ">" str2 " =" (str1>srt2)
    next1 = (getline str1 < file1)
    next2 = (getline str2 < file2)
    print
  }

Quote:
}

--------------------------------------- end of d.awk ----
and two files
------------------------------------------------- b1 ----
aaaa
bbbb
aaaa
-----------------------------------------  end of b1 ----
------------------------------------------------- b2 ----
aaaa
aaaa
bbbb
-----------------------------------------  end of b2 ----

after the command
     awk -f d.awk b1 b2
I got the following result

     aaaa==aaaa 1
     aaaa< bbbb 1
     bbbb< aaaa 0

     aaaa=aaaa =0
     aaaa<aaaa =0
     aaaa>aaaa =1

     bbbb=aaaa =0
     bbbb<aaaa =0
     bbbb>aaaa =1

     aaaa=bbbb =0
     aaaa<bbbb =0
     aaaa>bbbb =1

If I use constant strings everything fine, but if I read strings from
files, I got wrong results.

Why?

Thanks

Laszlo



Sun, 21 Mar 2004 19:26:57 GMT  
 Q: Compare lines of files

Quote:
> Hi!
<snip>
>     print str1 "=" str2 " =" (str1==srt2)

Typo here                             ^^^^

Quote:
>     print str1 "<" str2 " =" (str1<srt2)

Typo here                            ^^^^

Quote:
>     print str1 ">" str2 " =" (str1>srt2)

Typo here                            ^^^^
<snip>
Quote:

> If I use constant strings everything fine, but if I read strings from
> files, I got wrong results.

> Why?

Correct the typing errors above.

HTH
--
Peter S Tillier

Opinions expressed are my own and not necessarily
those of my employer.



Sun, 21 Mar 2004 21:50:00 GMT  
 Q: Compare lines of files

Quote:

> Correct the typing errors above.

Thanks a lot.

Laszlo



Sun, 21 Mar 2004 22:25:49 GMT  
 Q: Compare lines of files


Quote:

>> Correct the typing errors above.

>Thanks a lot.

>Laszlo

All programming errors are, in fact, typos.


Sun, 21 Mar 2004 23:07:33 GMT  
 Q: Compare lines of files

Quote:

>Hi!

>I have the following AWK program:
>---------------------------------------------- d.awk ----
>BEGIN{
>  print "aaaa==aaaa", ("aaaa"=="aaaa")
>  print "aaaa< bbbb", ("aaaa"<"bbbb")
>  print "bbbb< aaaa", ("bbbb" < "aaaa")
>  print

>  file1 = ARGV[1]
>  file2 = ARGV[2]
>  next1 = (getline str1 < file1)
>  next2 = (getline str2 < file2)
>  while (next1 && next2) {
>    print str1 "=" str2 " =" (str1==srt2)
>    print str1 "<" str2 " =" (str1<srt2)
>    print str1 ">" str2 " =" (str1>srt2)
>    next1 = (getline str1 < file1)
>    next2 = (getline str2 < file2)
>    print
>  }
>}
>--------------------------------------- end of d.awk ----
>and two files
>------------------------------------------------- b1 ----
>aaaa
>bbbb
>aaaa
>-----------------------------------------  end of b1 ----
>------------------------------------------------- b2 ----
>aaaa
>aaaa
>bbbb
>-----------------------------------------  end of b2 ----

>after the command
>     awk -f d.awk b1 b2
>I got the following result

>     aaaa==aaaa 1
>     aaaa< bbbb 1
>     bbbb< aaaa 0

>     aaaa=aaaa =0
>     aaaa<aaaa =0
>     aaaa>aaaa =1

>     bbbb=aaaa =0
>     bbbb<aaaa =0
>     bbbb>aaaa =1

>     aaaa=bbbb =0
>     aaaa<bbbb =0
>     aaaa>bbbb =1

>If I use constant strings everything fine, but if I read strings from
>files, I got wrong results.

>Why?

    print str1 "=" str2 " =" (str1==srt2)

try 'str2' instead of 'srt2' here

    print str1 "<" str2 " =" (str1<srt2)
    print str1 ">" str2 " =" (str1>srt2)

Quote:
>Laszlo

--
: ${L:-aura} # http://lf.8k.com:80
:            # http://lf.1accesshost.com


Mon, 22 Mar 2004 04:53:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How to compare two files line-by-line

2. Comparing file objects: what is compared?

3. newbie obj files Qs

4. Comparing 2 files to create a third file

5. comparing an input file with an output file

6. Comparing Lines In Awk (Can I do this:)

7. Compare lines

8. assignment and compare on same line?

9. Using EXPECT to compare numerous lines

10. reversing lines char by char, but not the line order in a file

11. Search file and print line + next line?

12. how to read text files line by line?

 

 
Powered by phpBB® Forum Software