我在Bash中有一个字符串:
string="My string"
Run Code Online (Sandbox Code Playgroud)
如何测试它是否包含另一个字符串?
if [ $string ?? 'foo' ]; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
??我的未知运营商在哪里?我是否使用echo grep?
if echo "$string" | grep 'foo'; then
echo "It's there!"
fi
Run Code Online (Sandbox Code Playgroud)
这看起来有点笨拙.
有没有办法在Unix中删除文件中的重复行?
我可以使用sort -u和uniq命令,但我想使用sed或awk.那可能吗?
我在Python中有一个实用程序脚本:
#!/usr/bin/env python
import sys
unique_lines = []
duplicate_lines = []
for line in sys.stdin:
if line in unique_lines:
duplicate_lines.append(line)
else:
unique_lines.append(line)
sys.stdout.write(line)
# optionally do something with duplicate_lines
Run Code Online (Sandbox Code Playgroud)
这个简单的功能(uniq无需先排序,稳定排序)必须作为简单的UNIX实用程序提供,不是吗?也许是管道中过滤器的组合?
询问的原因:在我无法从任何地方执行python的系统上需要此功能