我正在使用以下命令
curl -silent http://api.openstreetmap.org/api/0.6/relation/2919627 http://api.openstreetmap.org/api/0.6/relation/2919628 | grep node | awk '{print $3}' | uniq
Run Code Online (Sandbox Code Playgroud)
当我想知道为什么uniq
不删除重复项时。知道为什么吗?
有没有办法告诉sed
在每第二次出现时替换模式?或者至少每隔一行?(当然可以使用脚本,但我问自己是否sed
可以做到)。
编辑
我发现
sed -e "s/pattern/replacement/g;n"
Run Code Online (Sandbox Code Playgroud)
但它取代了每一次出现,而不是第二次。
例子
输入文件:
I have a pattern in each line
Also the second line has the pattern
Another pattern here
And -- you guess it -- a pattern
Run Code Online (Sandbox Code Playgroud)
期望的输出:
I have a pattern in each line
Also the second line has the replacement
Another pattern here
And -- you guess it -- a replacement
Run Code Online (Sandbox Code Playgroud)