Skip to main content
added 236 characters in body
Source Link
Shawn
  • 1.4k
  • 9
  • 9

Using aned one-liner:

printf "%s\n" '?OPERATIONAL^OPERATIONAL SYSTEMS TOMORROW:$?,$w' | ed -s arquivo

rewritesor with ex instead:

ex -sc '?^OPERATIONAL SYSTEMS TOMORROW:$?,$wq!' input.txt

these rewrite arquivo to save only everything from the last matching line to the end of the file.

Using a file-oriented tool like ed or ex instead of a stream-oriented one like sed or awk makes many non-trivial automated editing tasks much simpler because they can do things like search backwards from a cursor location.

Using aned one-liner:

printf "%s\n" '?OPERATIONAL SYSTEMS TOMORROW:?,$w' | ed -s arquivo

rewrites arquivo to save only everything from the last matching line to the end of the file.

Using aned one-liner:

printf "%s\n" '?^OPERATIONAL SYSTEMS TOMORROW:$?,$w' | ed -s arquivo

or with ex instead:

ex -sc '?^OPERATIONAL SYSTEMS TOMORROW:$?,$wq!' input.txt

these rewrite arquivo to save only everything from the last matching line to the end of the file.

Using a file-oriented tool like ed or ex instead of a stream-oriented one like sed or awk makes many non-trivial automated editing tasks much simpler because they can do things like search backwards from a cursor location.

Source Link
Shawn
  • 1.4k
  • 9
  • 9

Using aned one-liner:

printf "%s\n" '?OPERATIONAL SYSTEMS TOMORROW:?,$w' | ed -s arquivo

rewrites arquivo to save only everything from the last matching line to the end of the file.