use*_*332 -2 shell shell-script
我是这个论坛的新手,我有两个文件需要比较,这些文件没有分隔符,并且数据以位置方式存在,因此需要逐行比较每个字符。我使用了下面的 sdiff 命令,但它没有向我显示预期的输出,它只显示不同的行号,但不显示字符的位置。
sdiff file1 file2 | grep "|" > log file
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码,你能帮忙吗?
for i in `cat /home/okanung/test_handoff/testfile1`
do
for j in `cat /home/okanung/test_handoff/testfile2`
do
for ((k=0;k <=`echo $i | wc -c `;k++))
do
a=${i:k:1}
b=${j:k:1}
if [ "$a" != "$b" ]
then
lineno=`grep -n "$i" /home/okanung/test_handoff/testfile1 | cut -d ":" -f 1`
echo "mismatch is at line no $lineno at position $k" | sort -n | uniq -c >> /home/okanung/test_handoff/test_log_file
fi
done
done
done
Run Code Online (Sandbox Code Playgroud)
文件格式:06001234567800000009 20160226100TD22000002 04.00000.0000000000000030.000000000000028.800000 0000000000001.200000 0000000000000.4200000000000000000.4000000000000000000.020000 ?? 0000000000000.460000 ?? 0000000000000.440000 ?? 0000000000000.020000 ?? 0000000000000.000000 ??标准0 221-PASS率201603075 10UW0000054321AB00000361593804INR20160226EUR0010000010000000 ?? 00000030.00000000000 ?? 000000.0004.00004.00 ?? 000000000000
使用cmp
:
$ cat file1.txt
This file
is the same
as the other
$ cat file2.txt
This file
is almost the same
as the other
$ cmp file1.txt file2.txt
file1.txt file2.txt differ: char 14, line 2
Run Code Online (Sandbox Code Playgroud)
char 14
指文件中第一个不同的字符。
对于单词差异的直观表示,请使用wdiff
:
$ wdiff file1.txt file2.txt
This file
is {+almost+} the same
as the other
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3535 次 |
最近记录: |