How to modify this `printf` code to accept input in first to last order, or flip output?
1
vote
2
answers
241
views
Code below can, for example ...
[anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt
... take all of numbers within ...
[anony@mous-pc ~]$ cat file.txt
005
003
110
069
002
008
004
245
009
007
006
... and move desired numbers (or other strings) to top, **BUT in reverse order** of executed code ...
[anony@mous-pc ~]$ cat file.txt
002
004
006
008
005
003
110
069
245
009
007
... just so long as you give the order in reverse, the order will be first to last (opposite order), or ... others may call it top to bottom formatting ... so one more time, to achieve first to last order I had to execute this way ...
[anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt
> BUT, how can one input their numbers (or strings) in the order they
> intended for being first to last and still achieve first to last
> order?
>
> If not possible to change inputted results, would
sed
be able to
> change output results and flip or reverse them before saving
> file.txt
?
Asked by Anonymous
(533 rep)
May 21, 2019, 03:22 AM
Last activity: Apr 22, 2024, 09:41 AM
Last activity: Apr 22, 2024, 09:41 AM