Skip to main content
deleted 129 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

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 some.txt
005
003
110
069
002
008
004
245
009
007
006

... and move desired numbers wanted moved (or any other strings) to top in exact order given in code executed, like so:

[anony@mous-pc ~]$ cat some.txt
002
004
006
008
005
003
110
069
245
009
007

How can this code be reversed to make these numbers order at the bottom of the .txt rather than at the top?

Feel free to correct my question title if I am not stating the question properly according to proper Linux words & definitions.

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 some.txt
005
003
110
069
002
008
004
245
009
007
006

... and move desired numbers wanted moved (or any other strings) to top in exact order given in code executed, like so:

[anony@mous-pc ~]$ cat some.txt
002
004
006
008
005
003
110
069
245
009
007

How can this code be reversed to make these numbers order at the bottom of the .txt rather than at the top?

Feel free to correct my question title if I am not stating the question properly according to proper Linux words & definitions.

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 some.txt
005
003
110
069
002
008
004
245
009
007
006

... and move desired numbers wanted moved (or any other strings) to top in exact order given in code executed, like so:

[anony@mous-pc ~]$ cat some.txt
002
004
006
008
005
003
110
069
245
009
007

How can this code be reversed to make these numbers order at the bottom of the .txt rather than at the top?

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link
Anonymous
  • 533
  • 9
  • 16

How to modify this `printf` code to reverse it's action?

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 some.txt
005
003
110
069
002
008
004
245
009
007
006

... and move desired numbers wanted moved (or any other strings) to top in exact order given in code executed, like so:

[anony@mous-pc ~]$ cat some.txt
002
004
006
008
005
003
110
069
245
009
007

How can this code be reversed to make these numbers order at the bottom of the .txt rather than at the top?

Feel free to correct my question title if I am not stating the question properly according to proper Linux words & definitions.