这主要是出于好奇心,我试图拥有相同的行为:
echo -e "test1:test2:test3"| sed 's/:/\n/g' | grep 1
在单个sed
命令中。
我已经试过了
echo -e "test1:test2:test3"| sed -e "s/:/\n/g" -n "/1/p"
但我得到以下错误:
sed: can't read /1/p: No such file or directory
你知道如何修复这个问题并将不同类型的命令组合到单个sed
调用中吗?
当然,与真实的用例相比,这过于简单了,而且我知道我可以通过使用多个调用来解决问题,同样,这只是出于好奇。
编辑:我最感兴趣的是sed
工具,我已经知道如何使用其他工具,甚至是这些工具的组合。
EDIT2:这是一个更现实的脚本,更接近我想要实现的目标:
arch=linux64
base=https://chromedriver.storage.googleapis.com
split="<Contents>"
curl $base \
| sed -e 's/<Contents>/<Contents>\n/g' \
| grep $arch \
| sed -e 's/^<Key>\(.*\)\/chromedriver.*/\1/' \
| sort -V > out
我想要简化的是卷曲线,把它变成类似于:
curl $base \
| sed 's/<Contents>/<Contents>\n/g' -n '/1/p' -e 's/^<Key>\(.*\)\/chromedriver.*/\1/' \
| sort -V > out
https://stackoverflow.com/questions/56771698
复制相似问题