Your example script has a space before the statistics, but your example data is not displayed. This has a regex that assumes statistics are at the beginning of a line; if this is not true.
sed -n '/^Statistics |/h;/^Statistics |/!H;$!b;x;p'
When you see "Statistics", replace the hold space with the current row ( h ). Otherwise add to the hold space ( h ). If we are not at the end of the file, stop here ( b ). Print a hold space at the end of the file ( x extract the contents of the hold space, p print).
In a sed script, commands do not necessarily have a prefix at "address". This is most often a regular expression, but it can also be a line number. The address /^Statistics |/ selects all lines matching the regular expression; /^Statistics |/! selects strings that do not match the regular expression; and $! matches all lines except the last line in the file. For all input lines, commands are executed without an explicit address.
Edit Explain the script in more detail and add the following.
Note that if you need to transfer this to a remote host using ssh , you will need additional citation levels. One possible workaround for a solution, if it gets too complicated, is to save this script to a remote host and just ssh remotehost path/to/script . Another possible workaround is to change the addressing expressions so that they do not contain exclamation points (this is problematic on the command line, for example, in Bash).
sed -n '/^Statistics |/{h;b};H;${x;p}'
This is a bit easier!
The third possible workaround, if your stdin ssh pipeline is not tied to other things, should connect to the script from your local host.
echo '/^Statistics |/h;/^Statistics |/!H;$!b;x;p' | ssh remotehost sed -n -f - file
tripleee
source share