我有两个包含信息行的字符串.我想获得两个字符串中不同的行.示例:String1:
"This is line1
This is line2
This is line3"
Run Code Online (Sandbox Code Playgroud)
String2的:
"This is line1
This is linex
This is line2"
Run Code Online (Sandbox Code Playgroud)
结果预期:
diff string1 string2 is:
"This is line3"
diff string2 string1 is:
"This is linex"
Run Code Online (Sandbox Code Playgroud)
你可以使用comm:
$ str1="This is line1
> This is line2
> This is line3"
$ str2="This is line1
> This is linex
> This is line2"
$ comm -23 <(echo "$str1" | sort) <(echo "$str2" | sort)
This is line3
$ comm -23 <(echo "$str2" | sort) <(echo "$str1" | sort)
This is linex
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6672 次 |
| 最近记录: |