Skip to main content
added 181 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Use the t command after each s command to branch to the end of the script if a substitution was made:

sed -e 's/something/else/;t' \ -e 's/one/two/;t' \ -e 's/two/three/;t' <<<"one" 

Here, the t command after the last substitution is not needed, but if you generate this code automatically, there is no problem letting it suffix each s, even the last.

Use the t command after each s command to branch to the end of the script if a substitution was made:

sed -e 's/something/else/;t' \ -e 's/one/two/;t' \ -e 's/two/three/;t' <<<"one" 

Use the t command after each s command to branch to the end of the script if a substitution was made:

sed -e 's/something/else/;t' \ -e 's/one/two/;t' \ -e 's/two/three/;t' <<<"one" 

Here, the t command after the last substitution is not needed, but if you generate this code automatically, there is no problem letting it suffix each s, even the last.

Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Use the t command after each s command to branch to the end of the script if a substitution was made:

sed -e 's/something/else/;t' \ -e 's/one/two/;t' \ -e 's/two/three/;t' <<<"one"