How to move lines containing specific text to top of file in same order as code executed?Delete lines...

How long do Aarakocra live?

How does this piece of code determine array size without using sizeof( )?

Why are lawsuits between the President and Congress not automatically sent to the Supreme Court

Single word that parallels "Recent" when discussing the near future

Rushed passport - does my reason qualify?

Why aren't satellites disintegrated even though they orbit earth within their Roche Limits?

How do Ctrl+C and Ctrl+V work?

Why do academics prefer Mac/Linux?

Square spiral in Mathematica

Why do galaxies collide?

Why does the U.S military use mercenaries?

Physically unpleasant work environment

How can I fix the label locations on my tikzcd diagram?

Capital gains on stocks sold to take initial investment off the table

Why is the marginal distribution/marginal probability described as "marginal"?

Cannot remove door knob -- totally inaccessible!

Why does Taylor’s series “work”?

Is it standard for US-based universities to consider the ethnicity of an applicant during PhD admissions?

Divisor Rich and Poor Numbers

Do we see some Unsullied doing this in S08E05?

How was the blinking terminal cursor invented?

multiline equation inside a matrix that is a part of multiline equation

"Counterexample" for the Inverse function theorem

Solenoid fastest possible release - for how long should reversed polarity be applied?



How to move lines containing specific text to top of file in same order as code executed?


Delete lines containing repeated textInsert text in specific lines of a file?What is the most efficient way to move a large number of files that reside in a single directory?remove lines that contain a specific text in a fileInsert text in specific lines of a file? with special charactersAvoid output buffering for a command group (curly braces) in bash scriptAn Alias for Moving Files and Following Them to Their DestinationHow can I both extract a specific line in a text file as well as multiple lines containing a specific string?Move all words with a specific order to the top of the listmodify lines containing specific words/characters and not containing others






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







0















How to move lines containing specific text to top of file in same order as code executed?



Here is the code I have:



printf 'g?_001|_002|_003|_004|_005?m0nwqn' | ed -s target_file



( credit goes to steeldriver for helping me get this far. Truely an amazing user of this site! )




This moves them to the top like so:



name_003
name_005
name_004
name_002
name_001


or however order they were in originally, just to the top.



but I need them to be put in the same order as I have them in within the printf and ed code, so in this case, like:



name_001
name_002
name_003
name_004
name_005


Anyone familiar with printf and ed?



Thanks a lot!










share|improve this question































    0















    How to move lines containing specific text to top of file in same order as code executed?



    Here is the code I have:



    printf 'g?_001|_002|_003|_004|_005?m0nwqn' | ed -s target_file



    ( credit goes to steeldriver for helping me get this far. Truely an amazing user of this site! )




    This moves them to the top like so:



    name_003
    name_005
    name_004
    name_002
    name_001


    or however order they were in originally, just to the top.



    but I need them to be put in the same order as I have them in within the printf and ed code, so in this case, like:



    name_001
    name_002
    name_003
    name_004
    name_005


    Anyone familiar with printf and ed?



    Thanks a lot!










    share|improve this question



























      0












      0








      0


      1






      How to move lines containing specific text to top of file in same order as code executed?



      Here is the code I have:



      printf 'g?_001|_002|_003|_004|_005?m0nwqn' | ed -s target_file



      ( credit goes to steeldriver for helping me get this far. Truely an amazing user of this site! )




      This moves them to the top like so:



      name_003
      name_005
      name_004
      name_002
      name_001


      or however order they were in originally, just to the top.



      but I need them to be put in the same order as I have them in within the printf and ed code, so in this case, like:



      name_001
      name_002
      name_003
      name_004
      name_005


      Anyone familiar with printf and ed?



      Thanks a lot!










      share|improve this question
















      How to move lines containing specific text to top of file in same order as code executed?



      Here is the code I have:



      printf 'g?_001|_002|_003|_004|_005?m0nwqn' | ed -s target_file



      ( credit goes to steeldriver for helping me get this far. Truely an amazing user of this site! )




      This moves them to the top like so:



      name_003
      name_005
      name_004
      name_002
      name_001


      or however order they were in originally, just to the top.



      but I need them to be put in the same order as I have them in within the printf and ed code, so in this case, like:



      name_001
      name_002
      name_003
      name_004
      name_005


      Anyone familiar with printf and ed?



      Thanks a lot!







      linux bash shell-script text-processing sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 23 mins ago







      Anonymous User

















      asked 34 mins ago









      Anonymous UserAnonymous User

      516




      516






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use separate move commands:



          ex -sc 'g?_005?m0' -c 'g?_004?m0' -c 'g?_003?m0' -c 'g?_002?m0' -c 'g?_001?m0' -c wq target_file


          Note that:




          • I'm using ex (actually, Vim) here, not ed. You can specify the ex-commands in the command line using the -c option, so printf isn't needed.

          • The patterns must be in reverse order (005 gets moved to the top first, then 004, pushing down 005, then 003, pushing down both 004 and 005, ...)


          With printf and ed, maybe:



          (printf 'g?%s?m0n' {005..001}; printf 'wqn') |
          ed -s target_file





          share|improve this answer
























            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%2f519189%2fhow-to-move-lines-containing-specific-text-to-top-of-file-in-same-order-as-code%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Use separate move commands:



            ex -sc 'g?_005?m0' -c 'g?_004?m0' -c 'g?_003?m0' -c 'g?_002?m0' -c 'g?_001?m0' -c wq target_file


            Note that:




            • I'm using ex (actually, Vim) here, not ed. You can specify the ex-commands in the command line using the -c option, so printf isn't needed.

            • The patterns must be in reverse order (005 gets moved to the top first, then 004, pushing down 005, then 003, pushing down both 004 and 005, ...)


            With printf and ed, maybe:



            (printf 'g?%s?m0n' {005..001}; printf 'wqn') |
            ed -s target_file





            share|improve this answer




























              0














              Use separate move commands:



              ex -sc 'g?_005?m0' -c 'g?_004?m0' -c 'g?_003?m0' -c 'g?_002?m0' -c 'g?_001?m0' -c wq target_file


              Note that:




              • I'm using ex (actually, Vim) here, not ed. You can specify the ex-commands in the command line using the -c option, so printf isn't needed.

              • The patterns must be in reverse order (005 gets moved to the top first, then 004, pushing down 005, then 003, pushing down both 004 and 005, ...)


              With printf and ed, maybe:



              (printf 'g?%s?m0n' {005..001}; printf 'wqn') |
              ed -s target_file





              share|improve this answer


























                0












                0








                0







                Use separate move commands:



                ex -sc 'g?_005?m0' -c 'g?_004?m0' -c 'g?_003?m0' -c 'g?_002?m0' -c 'g?_001?m0' -c wq target_file


                Note that:




                • I'm using ex (actually, Vim) here, not ed. You can specify the ex-commands in the command line using the -c option, so printf isn't needed.

                • The patterns must be in reverse order (005 gets moved to the top first, then 004, pushing down 005, then 003, pushing down both 004 and 005, ...)


                With printf and ed, maybe:



                (printf 'g?%s?m0n' {005..001}; printf 'wqn') |
                ed -s target_file





                share|improve this answer













                Use separate move commands:



                ex -sc 'g?_005?m0' -c 'g?_004?m0' -c 'g?_003?m0' -c 'g?_002?m0' -c 'g?_001?m0' -c wq target_file


                Note that:




                • I'm using ex (actually, Vim) here, not ed. You can specify the ex-commands in the command line using the -c option, so printf isn't needed.

                • The patterns must be in reverse order (005 gets moved to the top first, then 004, pushing down 005, then 003, pushing down both 004 and 005, ...)


                With printf and ed, maybe:



                (printf 'g?%s?m0n' {005..001}; printf 'wqn') |
                ed -s target_file






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 18 mins ago









                murumuru

                38.2k591167




                38.2k591167






























                    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%2f519189%2fhow-to-move-lines-containing-specific-text-to-top-of-file-in-same-order-as-code%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

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...