How to reverse input order?reverse order of paragraphs in fileReverse order of dot-delimited elements in a stringreverse order in a csvOrder of printf?Reverse the order of first 3 digits in a lineFormatting date order in csv using awkorder words beside each otherHow to move lines containing specific text to top of file in same order as code executed?How to modify this `printf` code to reverse it's action?How to modify this `printf` code to accept input in first to last order, or flip output?

How should I introduce map drawing to my players?

Need to read my home electrical meter

My players want to grind XP but we're using milestone advancement

Dad jokes are fun

Should one buy new hardware after a system compromise?

Where's this lookout in Nova Scotia?

Are black holes spherical during merger?

What happened to boiled-off gases from the storage tanks at Launch Complex 39?

Is there an online tool which supports shared writing?

How can I tell if I'm being too picky as a referee?

Apt - strange requests to d16r8ew072anqo.cloudfront.net:80

Why does the hash of infinity have the digits of π?

Lady G's amazing mazings

Can I summon an otherworldly creature with the Gate spell without knowing its true name?

Sankey diagram: not getting the hang of it

Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?

Defining the standard model of PA so that a space alien could understand

Who is in charge of Wakanda?

Pirate democracy at its finest

Is "cool" appropriate or offensive to use in IMs?

What is the function of the corrugations on a section of the Space Shuttle's external tank?

Why would Ryanair allow me to book this journey through a third party, but not through their own website?

NIntegrate doesn't evaluate

Is it truly impossible to tell what a CPU is doing?



How to reverse input order?


reverse order of paragraphs in fileReverse order of dot-delimited elements in a stringreverse order in a csvOrder of printf?Reverse the order of first 3 digits in a lineFormatting date order in csv using awkorder words beside each otherHow to move lines containing specific text to top of file in same order as code executed?How to modify this `printf` code to reverse it's action?How to modify this `printf` code to accept input in first to last order, or flip output?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















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?m0n' 0005 0004 0003 0002 0001 ; printf 'wqn') | ed -s file.txt


However, I would like to do:



(printf 'g?%s?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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.










share|improve this question



















  • 1





    do you just want to reverse de line order? Why not use tac?

    – matsib.dev
    9 hours ago











  • Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

    – Anonymous
    8 hours ago







  • 3





    @AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

    – steeldriver
    8 hours ago











  • @steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

    – Anonymous
    7 hours ago

















2















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?m0n' 0005 0004 0003 0002 0001 ; printf 'wqn') | ed -s file.txt


However, I would like to do:



(printf 'g?%s?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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.










share|improve this question



















  • 1





    do you just want to reverse de line order? Why not use tac?

    – matsib.dev
    9 hours ago











  • Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

    – Anonymous
    8 hours ago







  • 3





    @AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

    – steeldriver
    8 hours ago











  • @steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

    – Anonymous
    7 hours ago













2












2








2








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?m0n' 0005 0004 0003 0002 0001 ; printf 'wqn') | ed -s file.txt


However, I would like to do:



(printf 'g?%s?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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.










share|improve this question
















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?m0n' 0005 0004 0003 0002 0001 ; printf 'wqn') | ed -s file.txt


However, I would like to do:



(printf 'g?%s?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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?m0n' 0001 0002 0003 0004 0005 ; printf 'wqn') | 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.







text-processing sed text-formatting printf ed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago







Anonymous

















asked 9 hours ago









AnonymousAnonymous

1167




1167







  • 1





    do you just want to reverse de line order? Why not use tac?

    – matsib.dev
    9 hours ago











  • Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

    – Anonymous
    8 hours ago







  • 3





    @AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

    – steeldriver
    8 hours ago











  • @steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

    – Anonymous
    7 hours ago












  • 1





    do you just want to reverse de line order? Why not use tac?

    – matsib.dev
    9 hours ago











  • Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

    – Anonymous
    8 hours ago







  • 3





    @AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

    – steeldriver
    8 hours ago











  • @steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

    – Anonymous
    7 hours ago







1




1





do you just want to reverse de line order? Why not use tac?

– matsib.dev
9 hours ago





do you just want to reverse de line order? Why not use tac?

– matsib.dev
9 hours ago













Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

– Anonymous
8 hours ago






Yes!! EXACTLY!! How can I achieve that? And could you do the same with this one which is similar? This outputs to bottom of file rather than top of file. ( printf 'g?%s?m$n' $3 | tac; echo 'wq'; ) | ed -s file.txt

– Anonymous
8 hours ago





3




3





@AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

– steeldriver
8 hours ago





@AnonymousUser it might be worth re-stating your goal with another example - based on your recent post history, you seem to be in "every problem is a nail" mode

– steeldriver
8 hours ago













@steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

– Anonymous
7 hours ago





@steeldriver Ohh. I'm not surprised you say that. How can I improve/change?

– Anonymous
7 hours ago










3 Answers
3






active

oldest

votes


















3














( printf 'g?%s?m0n' 0005 0004 0003 0002 0001 | tac ; printf 'wqn' ) | ed -s file.txt


This reverses the ed commands produced by the first printf.






share|improve this answer


















  • 1





    "This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

    – Anonymous
    7 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    7 hours ago






  • 1





    Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

    – Anonymous
    5 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    5 hours ago











  • hehe, thank you! :)

    – Anonymous
    5 hours ago


















4














Even though my suggestion with tac worked, I think that maybe, your are making this much harder than it is.



If you have file.txt, and you simply want to add some lines at the beginning of file.txt, say, lines you have in a header_file.txt, you can simply do this:



cat header_file.txt file.txt > new_playlist.txt


and done.






share|improve this answer























  • How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

    – Anonymous
    8 hours ago












  • this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

    – matsib.dev
    7 hours ago











  • I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

    – Anonymous
    7 hours ago






  • 1





    there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

    – matsib.dev
    6 hours ago











  • Cool cool man :)

    – Anonymous
    5 hours ago


















2














Instead of moving lines on-by-one to the top, you could move the one-by-one to the bottom (which preserves the desired order) and then move them as a group to the top. Taking it a step at a time:




  1. Insert a placeholder line (whose contents could be anything - the simplest is just an empty line) and then move the selected lines to the end of the file m$. (NOTE: I changed the g?...? reverse search to more conventional g/.../ - it doesn't actually matter which direction you search in.)



    $ printf '$ann.n'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ',pnqn'; | ed -s file.txt
    5575
    3585
    7774
    5385
    8658

    0001
    0002
    0003
    0004
    0005



  2. Now add a mark (kx) on the placeholder line, so that we can address lines x to $ and move them to the top using 'x,$m0:



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n,pnqn'; | ed -s file.txt

    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658



  3. Finally we need to remove the placeholder (which is now line 1):



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,pnqn'; | ed -s file.txt
    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658


Putting it all together and replacing ,p by wq to edit in place:



$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$
$ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,wqn'; | ed -s file.txt
$
$ cat file.txt
0001
0002
0003
0004
0005
5575
3585
7774
5385
8658





share|improve this answer























  • Now to make it all a one-liner, haha.

    – Anonymous
    6 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    6 hours ago











  • ... and even if it wasn't already a one-liner, that's what shell functions are for.

    – Kusalananda
    6 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f520640%2fhow-to-reverse-input-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














( printf 'g?%s?m0n' 0005 0004 0003 0002 0001 | tac ; printf 'wqn' ) | ed -s file.txt


This reverses the ed commands produced by the first printf.






share|improve this answer


















  • 1





    "This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

    – Anonymous
    7 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    7 hours ago






  • 1





    Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

    – Anonymous
    5 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    5 hours ago











  • hehe, thank you! :)

    – Anonymous
    5 hours ago















3














( printf 'g?%s?m0n' 0005 0004 0003 0002 0001 | tac ; printf 'wqn' ) | ed -s file.txt


This reverses the ed commands produced by the first printf.






share|improve this answer


















  • 1





    "This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

    – Anonymous
    7 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    7 hours ago






  • 1





    Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

    – Anonymous
    5 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    5 hours ago











  • hehe, thank you! :)

    – Anonymous
    5 hours ago













3












3








3







( printf 'g?%s?m0n' 0005 0004 0003 0002 0001 | tac ; printf 'wqn' ) | ed -s file.txt


This reverses the ed commands produced by the first printf.






share|improve this answer













( printf 'g?%s?m0n' 0005 0004 0003 0002 0001 | tac ; printf 'wqn' ) | ed -s file.txt


This reverses the ed commands produced by the first printf.







share|improve this answer












share|improve this answer



share|improve this answer










answered 8 hours ago









KusalanandaKusalananda

148k18278466




148k18278466







  • 1





    "This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

    – Anonymous
    7 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    7 hours ago






  • 1





    Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

    – Anonymous
    5 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    5 hours ago











  • hehe, thank you! :)

    – Anonymous
    5 hours ago












  • 1





    "This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

    – Anonymous
    7 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    7 hours ago






  • 1





    Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

    – Anonymous
    5 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    5 hours ago











  • hehe, thank you! :)

    – Anonymous
    5 hours ago







1




1





"This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

– Anonymous
7 hours ago





"This reverses the ed commands produced by the first printf." See, this guy knows what I asked. This is the answer that needs upvoting ...

– Anonymous
7 hours ago




1




1





THANK YOU SO DAMN MUCH!

– Anonymous
7 hours ago





THANK YOU SO DAMN MUCH!

– Anonymous
7 hours ago




1




1





Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

– Anonymous
5 hours ago






Hey can you do the same for ( printf 'g?%s?m$n' 0001 0002 0003 | tac ; printf 'wqn' ) | ed -s file.txt This one puts the numbers to the bottom of the file rather than at the top. The difference in code is to the right of the m as its a $ instead of a 0 However, the ordering is reversed and as you know I want it first to last OR top to bottom.

– Anonymous
5 hours ago














@AnonymousUser Remove the | tac.

– Kusalananda
5 hours ago





@AnonymousUser Remove the | tac.

– Kusalananda
5 hours ago













hehe, thank you! :)

– Anonymous
5 hours ago





hehe, thank you! :)

– Anonymous
5 hours ago













4














Even though my suggestion with tac worked, I think that maybe, your are making this much harder than it is.



If you have file.txt, and you simply want to add some lines at the beginning of file.txt, say, lines you have in a header_file.txt, you can simply do this:



cat header_file.txt file.txt > new_playlist.txt


and done.






share|improve this answer























  • How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

    – Anonymous
    8 hours ago












  • this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

    – matsib.dev
    7 hours ago











  • I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

    – Anonymous
    7 hours ago






  • 1





    there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

    – matsib.dev
    6 hours ago











  • Cool cool man :)

    – Anonymous
    5 hours ago















4














Even though my suggestion with tac worked, I think that maybe, your are making this much harder than it is.



If you have file.txt, and you simply want to add some lines at the beginning of file.txt, say, lines you have in a header_file.txt, you can simply do this:



cat header_file.txt file.txt > new_playlist.txt


and done.






share|improve this answer























  • How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

    – Anonymous
    8 hours ago












  • this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

    – matsib.dev
    7 hours ago











  • I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

    – Anonymous
    7 hours ago






  • 1





    there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

    – matsib.dev
    6 hours ago











  • Cool cool man :)

    – Anonymous
    5 hours ago













4












4








4







Even though my suggestion with tac worked, I think that maybe, your are making this much harder than it is.



If you have file.txt, and you simply want to add some lines at the beginning of file.txt, say, lines you have in a header_file.txt, you can simply do this:



cat header_file.txt file.txt > new_playlist.txt


and done.






share|improve this answer













Even though my suggestion with tac worked, I think that maybe, your are making this much harder than it is.



If you have file.txt, and you simply want to add some lines at the beginning of file.txt, say, lines you have in a header_file.txt, you can simply do this:



cat header_file.txt file.txt > new_playlist.txt


and done.







share|improve this answer












share|improve this answer



share|improve this answer










answered 8 hours ago









matsib.devmatsib.dev

20824




20824












  • How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

    – Anonymous
    8 hours ago












  • this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

    – matsib.dev
    7 hours ago











  • I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

    – Anonymous
    7 hours ago






  • 1





    there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

    – matsib.dev
    6 hours ago











  • Cool cool man :)

    – Anonymous
    5 hours ago

















  • How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

    – Anonymous
    8 hours ago












  • this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

    – matsib.dev
    7 hours ago











  • I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

    – Anonymous
    7 hours ago






  • 1





    there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

    – matsib.dev
    6 hours ago











  • Cool cool man :)

    – Anonymous
    5 hours ago
















How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

– Anonymous
8 hours ago






How does this reverse the order of the output from the first printf command? I thought > was to append additions to the file?

– Anonymous
8 hours ago














this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

– matsib.dev
7 hours ago





this doesn't revert the order of the output of printf... it was simply that, at the beginning, it was not clear at all what you were trying to do, so, one tries to help you in the best possible way with the information you provided.

– matsib.dev
7 hours ago













I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

– Anonymous
7 hours ago





I am terribly sorry if I offended. I don't see how I am making things harder than they are though. I have updated my question so that you can understand much better what it is I am asking. If you are giving your full positive effort in reading my question then I greatly appreciate your time.

– Anonymous
7 hours ago




1




1





there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

– matsib.dev
6 hours ago





there is no offense, and yeah, it's much clearer now. I'm glad that you solved your problem.

– matsib.dev
6 hours ago













Cool cool man :)

– Anonymous
5 hours ago





Cool cool man :)

– Anonymous
5 hours ago











2














Instead of moving lines on-by-one to the top, you could move the one-by-one to the bottom (which preserves the desired order) and then move them as a group to the top. Taking it a step at a time:




  1. Insert a placeholder line (whose contents could be anything - the simplest is just an empty line) and then move the selected lines to the end of the file m$. (NOTE: I changed the g?...? reverse search to more conventional g/.../ - it doesn't actually matter which direction you search in.)



    $ printf '$ann.n'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ',pnqn'; | ed -s file.txt
    5575
    3585
    7774
    5385
    8658

    0001
    0002
    0003
    0004
    0005



  2. Now add a mark (kx) on the placeholder line, so that we can address lines x to $ and move them to the top using 'x,$m0:



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n,pnqn'; | ed -s file.txt

    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658



  3. Finally we need to remove the placeholder (which is now line 1):



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,pnqn'; | ed -s file.txt
    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658


Putting it all together and replacing ,p by wq to edit in place:



$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$
$ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,wqn'; | ed -s file.txt
$
$ cat file.txt
0001
0002
0003
0004
0005
5575
3585
7774
5385
8658





share|improve this answer























  • Now to make it all a one-liner, haha.

    – Anonymous
    6 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    6 hours ago











  • ... and even if it wasn't already a one-liner, that's what shell functions are for.

    – Kusalananda
    6 hours ago















2














Instead of moving lines on-by-one to the top, you could move the one-by-one to the bottom (which preserves the desired order) and then move them as a group to the top. Taking it a step at a time:




  1. Insert a placeholder line (whose contents could be anything - the simplest is just an empty line) and then move the selected lines to the end of the file m$. (NOTE: I changed the g?...? reverse search to more conventional g/.../ - it doesn't actually matter which direction you search in.)



    $ printf '$ann.n'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ',pnqn'; | ed -s file.txt
    5575
    3585
    7774
    5385
    8658

    0001
    0002
    0003
    0004
    0005



  2. Now add a mark (kx) on the placeholder line, so that we can address lines x to $ and move them to the top using 'x,$m0:



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n,pnqn'; | ed -s file.txt

    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658



  3. Finally we need to remove the placeholder (which is now line 1):



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,pnqn'; | ed -s file.txt
    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658


Putting it all together and replacing ,p by wq to edit in place:



$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$
$ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,wqn'; | ed -s file.txt
$
$ cat file.txt
0001
0002
0003
0004
0005
5575
3585
7774
5385
8658





share|improve this answer























  • Now to make it all a one-liner, haha.

    – Anonymous
    6 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    6 hours ago











  • ... and even if it wasn't already a one-liner, that's what shell functions are for.

    – Kusalananda
    6 hours ago













2












2








2







Instead of moving lines on-by-one to the top, you could move the one-by-one to the bottom (which preserves the desired order) and then move them as a group to the top. Taking it a step at a time:




  1. Insert a placeholder line (whose contents could be anything - the simplest is just an empty line) and then move the selected lines to the end of the file m$. (NOTE: I changed the g?...? reverse search to more conventional g/.../ - it doesn't actually matter which direction you search in.)



    $ printf '$ann.n'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ',pnqn'; | ed -s file.txt
    5575
    3585
    7774
    5385
    8658

    0001
    0002
    0003
    0004
    0005



  2. Now add a mark (kx) on the placeholder line, so that we can address lines x to $ and move them to the top using 'x,$m0:



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n,pnqn'; | ed -s file.txt

    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658



  3. Finally we need to remove the placeholder (which is now line 1):



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,pnqn'; | ed -s file.txt
    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658


Putting it all together and replacing ,p by wq to edit in place:



$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$
$ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,wqn'; | ed -s file.txt
$
$ cat file.txt
0001
0002
0003
0004
0005
5575
3585
7774
5385
8658





share|improve this answer













Instead of moving lines on-by-one to the top, you could move the one-by-one to the bottom (which preserves the desired order) and then move them as a group to the top. Taking it a step at a time:




  1. Insert a placeholder line (whose contents could be anything - the simplest is just an empty line) and then move the selected lines to the end of the file m$. (NOTE: I changed the g?...? reverse search to more conventional g/.../ - it doesn't actually matter which direction you search in.)



    $ printf '$ann.n'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ',pnqn'; | ed -s file.txt
    5575
    3585
    7774
    5385
    8658

    0001
    0002
    0003
    0004
    0005



  2. Now add a mark (kx) on the placeholder line, so that we can address lines x to $ and move them to the top using 'x,$m0:



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n,pnqn'; | ed -s file.txt

    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658



  3. Finally we need to remove the placeholder (which is now line 1):



    $ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,pnqn'; | ed -s file.txt
    0001
    0002
    0003
    0004
    0005
    5575
    3585
    7774
    5385
    8658


Putting it all together and replacing ,p by wq to edit in place:



$ cat file.txt
5575
3585
0004
7774
0003
5385
0001
8658
0002
0005
$
$ printf '$ann.nkxn'; printf 'g/%s/m$n' 0001 0002 0003 0004 0005; printf ''x,$m0n1dn,wqn'; | ed -s file.txt
$
$ cat file.txt
0001
0002
0003
0004
0005
5575
3585
7774
5385
8658






share|improve this answer












share|improve this answer



share|improve this answer










answered 6 hours ago









steeldriversteeldriver

39.1k45491




39.1k45491












  • Now to make it all a one-liner, haha.

    – Anonymous
    6 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    6 hours ago











  • ... and even if it wasn't already a one-liner, that's what shell functions are for.

    – Kusalananda
    6 hours ago

















  • Now to make it all a one-liner, haha.

    – Anonymous
    6 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    6 hours ago











  • ... and even if it wasn't already a one-liner, that's what shell functions are for.

    – Kusalananda
    6 hours ago
















Now to make it all a one-liner, haha.

– Anonymous
6 hours ago





Now to make it all a one-liner, haha.

– Anonymous
6 hours ago













@AnonymousUser it is ...

– steeldriver
6 hours ago





@AnonymousUser it is ...

– steeldriver
6 hours ago













... and even if it wasn't already a one-liner, that's what shell functions are for.

– Kusalananda
6 hours ago





... and even if it wasn't already a one-liner, that's what shell functions are for.

– Kusalananda
6 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f520640%2fhow-to-reverse-input-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480