One can do it e.g. with sed
as follows:
# Including special characters
echo "libtiff5/**xenial-infra-security**|4.0.6-1ubuntu0.8+esm3" | sed 's/\/\(.*\)|//g'
# Output: libtiff54.0.6-1ubuntu0.8+esm3
# Excluding special characters
echo "libtiff5/**xenial-infra-security**|4.0.6-1ubuntu0.8+esm3" | sed 's/\/\(.*\)|/\/|/g'
# Output: libtiff5/|4.0.6-1ubuntu0.8+esm3
or if you have your text in e.g. file.txt
:
sed -e 's/\/\(.*\)|//g' -i file.txt
cat file.txt
# Output:
# libtiff54.0.6-1ubuntu0.8+esm3
# tzdata2022c-0ubuntu0.16.04+esm1
P.S. If you want to replace the strings between two special charachters with e.g. -
for readability:
echo "libtiff5/**xenial-infra-security**|4.0.6-1ubuntu0.8+esm3" | sed 's/\/\(.*\)|/-/g'
#Output: libtiff5-4.0.6-1ubuntu0.8+esm3
grep ... | awk ...
is an anti-pattern. Probably this could be done with a singleawk
(orsed
) call. What are the lines containing the stringxenial-infra-security
in the file (demo.log) ?