The following code provides a backwards output when inputted as first to last, so input is required to be in reverse. How can this be flipped/reversed?
EDITED on 2019-05-23_07:52:04
(printf 'g?%s?m0\n' 0005 0004 0003 0002 0001 ; printf 'wq\n') | ed -s file.txt
However, I would like to do:
(printf 'g?%s?m0\n' 0001 0002 0003 0004 0005 ; printf 'wq\n') | ed -s file.txt
and get output order at the top of file.txt
like this:
0001
0002
0003
0004
0005
file.txt
is a playlist for ffmpeg
and the zero padded numbers above are some chosen filenames of videos. The playlist has a bunch of filenames/videos already in it and I'd like to move a few to the top before compiling. However, not be required to input them in reverse order like the printf
command requires if first to last ordering is desired.
UPDATED on 2019-05-23_07:54:27
$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$ (printf 'g?%s?m0\n' 0001 0002 0003 0004 0005 ; printf 'wq\n') | ed -s file.txt
$ cat file.txt
0005
0004
0003
0002
0001
9374
4845
4834
4883
5848
Take note of the last cat
command and the ordering of the output.
line
order? Why not usetac
?( printf 'g?%s?m$\n' $3 | tac; echo 'wq'; ) | ed -s file.txt
tail -r
reverses the line order of its input.