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?

What was the idiom for something that we take without a doubt?

USPS Back Room - Trespassing?

Count Even Digits In Number

Why does Mjolnir fall down in Age of Ultron but not in Endgame?

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

Am I a new writer?

Of strange atmospheres - the survivable but unbreathable

Why did Theresa May offer a vote on a second Brexit referendum?

Is there an online tool which supports shared writing?

How to respond to upset student?

Is it legal to have an abortion in another state or abroad?

Do I need full recovery mode when I have multiple daily backup?

Why were helmets and other body armour not commonplace in the 1800s?

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

The art of clickbait captions

Why did Jon Snow do this immoral act if he is so honorable?

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

A steel cutting sword?

Where have Brexit voters gone?

Need to read my home electrical meter

Did this character show any indication of wanting to rule before S8E6?

Is there a simple example that empirical evidence is misleading?

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

Do photons bend spacetime or not?



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
    10 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
    9 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
    9 hours ago











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

    – Anonymous
    8 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
    10 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
    9 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
    9 hours ago











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

    – Anonymous
    8 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 7 hours ago







Anonymous

















asked 10 hours ago









AnonymousAnonymous

1167




1167







  • 1





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

    – matsib.dev
    10 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
    9 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
    9 hours ago











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

    – Anonymous
    8 hours ago












  • 1





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

    – matsib.dev
    10 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
    9 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
    9 hours ago











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

    – Anonymous
    8 hours ago







1




1





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

– matsib.dev
10 hours ago





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

– matsib.dev
10 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
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
9 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
9 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
9 hours ago













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

– Anonymous
8 hours ago





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

– Anonymous
8 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
    9 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    8 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
    6 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    6 hours ago











  • hehe, thank you! :)

    – Anonymous
    6 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
    9 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
    9 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
    8 hours ago






  • 1





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

    – matsib.dev
    7 hours ago











  • Cool cool man :)

    – Anonymous
    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
    7 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    7 hours ago











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

    – Kusalananda
    7 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
    9 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    8 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
    6 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    6 hours ago











  • hehe, thank you! :)

    – Anonymous
    6 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
    9 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    8 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
    6 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    6 hours ago











  • hehe, thank you! :)

    – Anonymous
    6 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 9 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
    9 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    8 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
    6 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    6 hours ago











  • hehe, thank you! :)

    – Anonymous
    6 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
    9 hours ago






  • 1





    THANK YOU SO DAMN MUCH!

    – Anonymous
    8 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
    6 hours ago












  • @AnonymousUser Remove the | tac.

    – Kusalananda
    6 hours ago











  • hehe, thank you! :)

    – Anonymous
    6 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
9 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
9 hours ago




1




1





THANK YOU SO DAMN MUCH!

– Anonymous
8 hours ago





THANK YOU SO DAMN MUCH!

– Anonymous
8 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
6 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
6 hours ago














@AnonymousUser Remove the | tac.

– Kusalananda
6 hours ago





@AnonymousUser Remove the | tac.

– Kusalananda
6 hours ago













hehe, thank you! :)

– Anonymous
6 hours ago





hehe, thank you! :)

– Anonymous
6 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
    9 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
    9 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
    8 hours ago






  • 1





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

    – matsib.dev
    7 hours ago











  • Cool cool man :)

    – Anonymous
    6 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
    9 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
    9 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
    8 hours ago






  • 1





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

    – matsib.dev
    7 hours ago











  • Cool cool man :)

    – Anonymous
    6 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 9 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
    9 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
    9 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
    8 hours ago






  • 1





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

    – matsib.dev
    7 hours ago











  • Cool cool man :)

    – Anonymous
    6 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
    9 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
    9 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
    8 hours ago






  • 1





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

    – matsib.dev
    7 hours ago











  • Cool cool man :)

    – Anonymous
    6 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
9 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
9 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
9 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
9 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
8 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
8 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
7 hours ago





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

– matsib.dev
7 hours ago













Cool cool man :)

– Anonymous
6 hours ago





Cool cool man :)

– Anonymous
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
    7 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    7 hours ago











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

    – Kusalananda
    7 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
    7 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    7 hours ago











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

    – Kusalananda
    7 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 7 hours ago









steeldriversteeldriver

39.1k45491




39.1k45491












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

    – Anonymous
    7 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    7 hours ago











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

    – Kusalananda
    7 hours ago

















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

    – Anonymous
    7 hours ago











  • @AnonymousUser it is ...

    – steeldriver
    7 hours ago











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

    – Kusalananda
    7 hours ago
















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

– Anonymous
7 hours ago





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

– Anonymous
7 hours ago













@AnonymousUser it is ...

– steeldriver
7 hours ago





@AnonymousUser it is ...

– steeldriver
7 hours ago













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

– Kusalananda
7 hours ago





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

– Kusalananda
7 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

Log på Navigationsmenu

Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

Nuuk Indholdsfortegnelse Etyomologi | Historie | Geografi | Transport og infrastruktur | Politik og administration | Uddannelsesinstitutioner | Kultur | Venskabsbyer | Noter | Eksterne henvisninger | Se også | Navigationsmenuwww.sermersooq.gl64°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.75064°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.750DMI - KlimanormalerSalmonsen, s. 850Grønlands Naturinstitut undersøger rensdyr i Akia og Maniitsoq foråret 2008Grønlands NaturinstitutNy vej til Qinngorput indviet i dagAntallet af biler i Nuuk må begrænsesNy taxacentral mødt med demonstrationKøreplan. Rute 1, 2 og 3SnescootersporNuukNord er for storSkoler i Kommuneqarfik SermersooqAtuarfik Samuel KleinschmidtKangillinguit AtuarfiatNuussuup AtuarfiaNuuk Internationale FriskoleIlinniarfissuaq, Grønlands SeminariumLedelseÅrsberetning for 2008Kunst og arkitekturÅrsberetning for 2008Julie om naturenNuuk KunstmuseumSilamiutGrønlands Nationalmuseum og ArkivStatistisk ÅrbogGrønlands LandsbibliotekStore koncerter på stribeVandhund nummer 1.000.000Kommuneqarfik Sermersooq – MalikForsidenVenskabsbyerLyngby-Taarbæk i GrønlandArctic Business NetworkWinter Cities 2008 i NuukDagligt opdaterede satellitbilleder fra NuukområdetKommuneqarfik Sermersooqs hjemmesideTurist i NuukGrønlands Statistiks databankGrønlands Hjemmestyres valgresultaterrrWorldCat124325457671310-5