String Sed是否删除角色第一个和第二个实例之间的所有内容?
我对sed不是很有经验,但是如果我有这样一个字符串:String Sed是否删除角色第一个和第二个实例之间的所有内容?,string,bash,replace,sed,String,Bash,Replace,Sed,我对sed不是很有经验,但是如果我有这样一个字符串: asdf | this is something | something else | nothing | qwerty 我可以删除|的第一个和第二个实例之间的所有内容,以及其中一个吗 理想的输出是: asdf | something else | nothing | qwerty 我尝试了sed的//code*//2',但这只删除了第二个管道 谢谢s/|[^ |]*|/|/应该做这项工作 echo 'asdf | this is som
asdf | this is something | something else | nothing | qwerty
我可以删除|
的第一个和第二个实例之间的所有内容,以及其中一个吗
理想的输出是:
asdf | something else | nothing | qwerty
我尝试了sed的//code*//2',但这只删除了第二个管道
谢谢
s/|[^ |]*|/|/
应该做这项工作
echo 'asdf | this is something | something else | nothing | qwerty' |
sed 's/|[^|]*|/|/'
asdf | something else | nothing | qwerty
选中此项:
sed 's/|[^|]*//'
以你为例
kent$ sed 's/|[^|]*//' <<<"asdf | this is something | something else | nothing | qwerty"
asdf | something else | nothing | qwerty
kent$sed's/|[^ |]*/'也可以使用awk完成:
awk -F '|' -v OFS='|' '{sub($2 " *\\|", "")}1' <<< "$str"
asdf | something else | nothing | qwerty
echo "${str%%|*}|${str#*|*|}"
asdf | something else | nothing | qwerty