We can't install anything that is not available from the vendor itself,
I'm a corporate Linux user
Hello
@Diputs.
In the following are two methods to address the query in post #1:
isn't there a tool for comparison of lines, and to tell me : hey, character 76 on the line is different !
Since you mentioned in post #6 that the git tool was not available to you, I believe the following achieves the result you are seeking using tools usually provided in default installations of linux, in this case, the coreutils and diffutils packages. Hopefully that will alleviate the issue of absent tools.
In this first approach, the two lines being compared are copied to a file each in /tmp where they reside having been subject to the command: "fold -1" which changes them by placing each character on a separate line in the system's /tmp directory (but it could be anywhere else that was available). These files in /tmp are equivalent in vertical line number to the character number in the original horizontal file. Then the files are compared with the diff command which outputs the results and then the files are removed from /tmp:
Code:
[tom@min ~]$ cat file1
the quick brown fox jumps over the lazy dog
[tom@min ~]$ cat file3
the quick brown fox jumps over the hazy hog
[tom@min ~]$
[tom@min ~]$ cat file1 | fold -1 > /tmp/file1f; cat file3 | fold -1 > /tmp/file3f ; diff /tmp/file1f /tmp/file3f ;rm /tmp/file*f
36c36
< l
---
> h
41c41
< d
---
> h
The results show that files differ at the 36th character, where the letter l has been replaced by the letter h, and at the 41st character where the letter d has been replaced by the letter h. The results can be verified by inspecting the original files.
The second approach uses the command: cmp which ouputs the differences at the byte number, which is equivalent to the character number in the first method above since each character takes up a single byte. The same files are used here as in the above example.
In the first run of the comparison with the command: cmp, the first difference between the files is identified, and the altered character (a letter in this case) is identified with its octal number 154 for l, and it's replacement identified similarly with the octal 150 for h. The octal numbers can be checked in the ascii manpage:
Code:
[tom@min ~]$ cmp -b file1 file3
file1 file3 differ: byte 36, line 1 is 154 l 150 h
The cmp command, by default, stops after the first difference is detected, so if there are more differences, one needs to reapply the command, skipping the part of the line that has already been observed by the command. Therefore, in the following, the first 36 bytes are skipped in both lines, so that the next section of the lines can be compared to identify any more differences:
Code:
[tom@min ~]$ cmp -b -i 36:36 file1 file3
file1 file3 differ: byte 5, line 1 is 144 d 150 h
In this case the cmp command has correctly identified the second difference in the lines it is looking at, but note that it has started counting from 1 at the skip point of 36, so it detected the next difference at byte 5, that is, five places further along from the 36th byte. Since 36 and 5 add up up to 41, the next difference identified is actually at the 41st byte, which is the same result as the first example shown above, bearing in mind that one byte is equivalent to one character in this case.
The above examples can be scripted or put into functions to make them more economical for use rather that be used in the long form shown here for purposes of clear exposition ... hopefully
YMMV