Bash-sed-examples: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Examples of using sed for different jobs * Remove all of a string until first match <pre> echo "1=2=3" | sed 's/[^=]*=//' 2=3 </pre> [https://unix.stackexchange.com/questions...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
Examples of using sed for different jobs | Examples of using sed for different jobs | ||
==Remove all of a string until first match== | |||
<pre> | <pre> | ||
echo "1=2=3" | sed 's/[^=]*=//' | echo "1=2=3" | sed 's/[^=]*=//' | ||
Line 8: | Line 8: | ||
[https://unix.stackexchange.com/questions/232657/delete-till-first-occurrence-of-colon-using-sed/232658| Stackexchange Details] | [https://unix.stackexchange.com/questions/232657/delete-till-first-occurrence-of-colon-using-sed/232658| Stackexchange Details] | ||
==Remove all after LAST match== | |||
<pre> | |||
echo "foo.bar.baz" | sed -e 's/\.[^.]*$//' | |||
foo.bar | |||
</pre> | |||
[[Category:bash]] | [[Category:bash]] |
Latest revision as of 05:17, 8 July 2024
Examples of using sed for different jobs
Remove all of a string until first match
echo "1=2=3" | sed 's/[^=]*=//' 2=3
Remove all after LAST match
echo "foo.bar.baz" | sed -e 's/\.[^.]*$//' foo.bar