Reputation: 1666
I'm not very experienced with sed, but If I have a string like this:
asdf | this is something | something else | nothing | qwerty
can I remove everything between the first and second instances of |
, plus one of them?
The ideal output would be:
asdf | something else | nothing | qwerty
I tried sed 's/|*|//2'
, but this only removes the second pipe.
Thanks
Upvotes: 2
Views: 1541
Reputation: 784908
Can be done using awk also:
awk -F '|' -v OFS='|' '{sub($2 " *\\|", "")}1' <<< "$str"
asdf | something else | nothing | qwerty
Using pure BASH:
echo "${str%%|*}|${str#*|*|}"
asdf | something else | nothing | qwerty
Upvotes: 2
Reputation: 195029
check this:
sed 's/|[^|]*//'
with your example
kent$ sed 's/|[^|]*//' <<<"asdf | this is something | something else | nothing | qwerty"
asdf | something else | nothing | qwerty
Upvotes: 1
Reputation: 23374
s/|[^|]*|/|/
should do the job
echo 'asdf | this is something | something else | nothing | qwerty' |
sed 's/|[^|]*|/|/'
asdf | something else | nothing | qwerty
Upvotes: 2