您好,我如何从文件中读取每一行并将其与其他文件进行比较...实际上该文件应该从命令行获取...请帮助我
if [[-f $@ ]];
then
for "$line" in $@;
do
if grep "^$line" /etc/passwd > /dev/null;
then IFS=":";
read usr pwd uid gid gcos home shell < <(grep "^$user" /etc/passwd);
IFS=",";
read name <<< "$gcos";
printf "UID:%-10s Name:%s\n" "$uid" "$name";
else
echo "No User"
fi
done
fi
答案1
您好,我如何从文件中读取每一行并将其与其他文件进行比较。
如果您只是想比较两个文件,我可以建议:
选项1差异=> 并排合并文件差异
sdiff file1 file2
示例输出:
abcdev abcdev
abcdev abcdev
abcdev abcdev
abcdev | abcde33
选项#2差异=> 逐行比较文件
diff file1 file2
示例输出:
4c4
< abcdev
---
> abcde33
选项#3维姆迪夫=> 使用 Vim 编辑文件的两个、三个或四个版本并显示差异
vimdiff file1 file2
示例屏幕(您可以在仍然看到差异的同时编辑文件):
选项#4grep=> 打印与模式匹配的行
grep -Fxvf file1 file2
标志细分:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
示例输出:
abcde33