smc*_*smc 0 shell sed awk shell-script
如果以下文件在所有行中包含相同的内容,则应打印“内容相同”。
$ cat file
example-line
example-line
example-line
Run Code Online (Sandbox Code Playgroud)
如果任何一行与其他行不同,那么它应该打印“内容不同”
例如
$ cat file
example-line
somethingelse
example-line
Run Code Online (Sandbox Code Playgroud)
将打印“内容不同”。
使用uniq
:
uniq -c testfile | [ $(wc -l) -eq 1 ] && echo 'contents are the same' || echo 'contents are different'