How can I adjust nth number in a line?Is there a command line tool to insert line breaks into a long string?sed: append line and number outputFilter file by line numberInsert text at specific line numberSplit text file in random halves based on categorydelete from beginning of file to nth occurrence of patternGet line number from byte offsetHow to use 'itextESC' when using ex as a text editor in command line?print everything before/after the nth matching lineSpecifically lower case email-addresses only

Dollar cost averaging vs buy low/sell high

How can you weaponize a thermos?

Miniseries in post-rapture US with good/evil conflict

How does "unlimited holidays" in practice work?

Pointlessly recurse down the alphabet

What mathematics activities get students physically moving?

What's a good use case for SELECT * in production code?

"No, your taste is (not) good"

Why is SpaceX not also working on a smaller version of Starship?

Homework Help on Simple Markov Chain

Why Philipine 113 /Boeing 777 didnt dump fuel prior to forced landing?

Why would a berry have a slow-acting poison?

Why would Earth be long-term unsuitable for an advanced alien species that's already colonized it?

How often are there lunar eclipses on Jupiter

What does "Massage with salt" mean in a recipe?

What kind of structure is an ISP?

Is Stoch enriched in Met?

Bought a book that is in the public domain ... but the T&A of company says I can't redistribute it

Draw ribbon with variable bending points

Why is it runway "1" instead of "01" in America?

MS BASIC, access a DIMed variable with no index?

Suppose I capture encrypted data that I want to decrypt. Could I use a server farm to decrypt?

Combining two plots with separate frame tick styles

Plane ticket price went down by 40% two weeks after I booked it. Is there anything I can do to get a refund?



How can I adjust nth number in a line?


Is there a command line tool to insert line breaks into a long string?sed: append line and number outputFilter file by line numberInsert text at specific line numberSplit text file in random halves based on categorydelete from beginning of file to nth occurrence of patternGet line number from byte offsetHow to use 'itextESC' when using ex as a text editor in command line?print everything before/after the nth matching lineSpecifically lower case email-addresses only






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









4


















File contents:



RANDOM TEXT num1=400 num2=15 RANDOM TEXT
RANDOM TEXT num1=300 num2=10 RANDOM TEXT
RANDOM TEXT num1=200 num2=5 RANDOM TEXT


I would like to subtract 5 for each num2 per line like so:



RANDOM TEXT num1=400 num2=10 RANDOM TEXT
RANDOM TEXT num1=300 num2=5 RANDOM TEXT
RANDOM TEXT num1=200 num2=0 RANDOM TEXT


Pure bash is preferred, but no biggie if another GNU tool does it better.










share|improve this question






















  • 4





    Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

    – Jeff Schaller
    Oct 16 at 16:57











  • Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

    – steeldriver
    Oct 16 at 17:42











  • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

    – TuxForLife
    Oct 16 at 17:48











  • Is num2= column always goes as 4th column?

    – RomanPerekhrest
    Oct 16 at 18:11

















4


















File contents:



RANDOM TEXT num1=400 num2=15 RANDOM TEXT
RANDOM TEXT num1=300 num2=10 RANDOM TEXT
RANDOM TEXT num1=200 num2=5 RANDOM TEXT


I would like to subtract 5 for each num2 per line like so:



RANDOM TEXT num1=400 num2=10 RANDOM TEXT
RANDOM TEXT num1=300 num2=5 RANDOM TEXT
RANDOM TEXT num1=200 num2=0 RANDOM TEXT


Pure bash is preferred, but no biggie if another GNU tool does it better.










share|improve this question






















  • 4





    Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

    – Jeff Schaller
    Oct 16 at 16:57











  • Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

    – steeldriver
    Oct 16 at 17:42











  • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

    – TuxForLife
    Oct 16 at 17:48











  • Is num2= column always goes as 4th column?

    – RomanPerekhrest
    Oct 16 at 18:11













4













4









4


0






File contents:



RANDOM TEXT num1=400 num2=15 RANDOM TEXT
RANDOM TEXT num1=300 num2=10 RANDOM TEXT
RANDOM TEXT num1=200 num2=5 RANDOM TEXT


I would like to subtract 5 for each num2 per line like so:



RANDOM TEXT num1=400 num2=10 RANDOM TEXT
RANDOM TEXT num1=300 num2=5 RANDOM TEXT
RANDOM TEXT num1=200 num2=0 RANDOM TEXT


Pure bash is preferred, but no biggie if another GNU tool does it better.










share|improve this question
















File contents:



RANDOM TEXT num1=400 num2=15 RANDOM TEXT
RANDOM TEXT num1=300 num2=10 RANDOM TEXT
RANDOM TEXT num1=200 num2=5 RANDOM TEXT


I would like to subtract 5 for each num2 per line like so:



RANDOM TEXT num1=400 num2=10 RANDOM TEXT
RANDOM TEXT num1=300 num2=5 RANDOM TEXT
RANDOM TEXT num1=200 num2=0 RANDOM TEXT


Pure bash is preferred, but no biggie if another GNU tool does it better.







text-processing command-line regular-expression numeric-data






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 16 at 17:15









Jeff Schaller

52.3k11 gold badges76 silver badges172 bronze badges




52.3k11 gold badges76 silver badges172 bronze badges










asked Oct 16 at 16:53









TuxForLifeTuxForLife

1,3197 silver badges16 bronze badges




1,3197 silver badges16 bronze badges










  • 4





    Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

    – Jeff Schaller
    Oct 16 at 16:57











  • Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

    – steeldriver
    Oct 16 at 17:42











  • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

    – TuxForLife
    Oct 16 at 17:48











  • Is num2= column always goes as 4th column?

    – RomanPerekhrest
    Oct 16 at 18:11












  • 4





    Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

    – Jeff Schaller
    Oct 16 at 16:57











  • Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

    – steeldriver
    Oct 16 at 17:42











  • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

    – TuxForLife
    Oct 16 at 17:48











  • Is num2= column always goes as 4th column?

    – RomanPerekhrest
    Oct 16 at 18:11







4




4





Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

– Jeff Schaller
Oct 16 at 16:57





Bash is not a good text editor; would you be satisfied with calling the proper tool from bash?

– Jeff Schaller
Oct 16 at 16:57













Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

– steeldriver
Oct 16 at 17:42





Are the separators between RANDOM and TEXT the same as those between the numerical columns, or do you have tab-separated data in which some columns contain spaces?

– steeldriver
Oct 16 at 17:42













In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

– TuxForLife
Oct 16 at 17:48





In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

– TuxForLife
Oct 16 at 17:48













Is num2= column always goes as 4th column?

– RomanPerekhrest
Oct 16 at 18:11





Is num2= column always goes as 4th column?

– RomanPerekhrest
Oct 16 at 18:11










4 Answers
4






active

oldest

votes


















6



















Using awk:



awk ' for (i=1;i<=NF;i++) if ($i ~ /num2=/) sub(/num2=/, "", $i); $i="num2="$i-5; print ' file


This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:



  1. Remove num2= - sub(/num2=/, "", $i)

  2. Redefine that column as num2=oldnum-5 - $i="num2="$i-5

  3. Print the line - print





share|improve this answer




























  • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

    – TuxForLife
    Oct 16 at 17:01











  • @TuxForLife: I've updated the answer.

    – Jesse_b
    Oct 16 at 17:05






  • 1





    Works like a charm, thanks Jesse

    – TuxForLife
    Oct 16 at 17:10


















5



















perl:



perl -pe 's/(?<=num2=)(d+)/$1 - 5/e' file


To store the contents back into the file:



perl -i -pe ...





share|improve this answer

































    4



















    [Just because I'm trying to become more familiar with Miller - it requires some jumping through hoops to get the heterogeneous output]:



    $ mlr --fs ' ' --repifs --ocsvlite --headerless-csv-output put '
    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
    ' file
    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
    RANDOM TEXT num1=200 num2=0 RANDOM TEXT


    If the input is actually TSV in which some columns may contain spaces, then



    $ mlr --fs 't' --ocsvlite --headerless-csv-output put '
    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
    ' file
    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
    RANDOM TEXT num1=200 num2=0 RANDOM TEXT





    share|improve this answer

































      0



















      Using Vim:



      vim +'g/^/exe "norm! 3Wf=5<C-A>"' +wq file


      The first + argument runs a series of normal mode operations on each line to increment the number 5 times. It uses a :global command to run this on every line. Simply using :normal with a range %norm would be simpler if we weren't using CTRLA to increment the number, but in order to (easily) pass this control character into Vim we build the command as a string to run with :execute, and thus we need the :global.



      The second + argument simply saves the file.



      If the format of RANDOM TEXT is less regular (or if you just prefer regular expressions), you could instead use a :substitute command:



      vim +'%s/num2=zsd+/=submatch(0) + 5' +wq file


      This uses a :substitute command to replace the N part of num2=N with the existing value plus five.






      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/4.0/"u003ecc by-sa 4.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%2f547119%2fhow-can-i-adjust-nth-number-in-a-line%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown


























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6



















        Using awk:



        awk ' for (i=1;i<=NF;i++) if ($i ~ /num2=/) sub(/num2=/, "", $i); $i="num2="$i-5; print ' file


        This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:



        1. Remove num2= - sub(/num2=/, "", $i)

        2. Redefine that column as num2=oldnum-5 - $i="num2="$i-5

        3. Print the line - print





        share|improve this answer




























        • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

          – TuxForLife
          Oct 16 at 17:01











        • @TuxForLife: I've updated the answer.

          – Jesse_b
          Oct 16 at 17:05






        • 1





          Works like a charm, thanks Jesse

          – TuxForLife
          Oct 16 at 17:10















        6



















        Using awk:



        awk ' for (i=1;i<=NF;i++) if ($i ~ /num2=/) sub(/num2=/, "", $i); $i="num2="$i-5; print ' file


        This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:



        1. Remove num2= - sub(/num2=/, "", $i)

        2. Redefine that column as num2=oldnum-5 - $i="num2="$i-5

        3. Print the line - print





        share|improve this answer




























        • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

          – TuxForLife
          Oct 16 at 17:01











        • @TuxForLife: I've updated the answer.

          – Jesse_b
          Oct 16 at 17:05






        • 1





          Works like a charm, thanks Jesse

          – TuxForLife
          Oct 16 at 17:10













        6















        6











        6









        Using awk:



        awk ' for (i=1;i<=NF;i++) if ($i ~ /num2=/) sub(/num2=/, "", $i); $i="num2="$i-5; print ' file


        This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:



        1. Remove num2= - sub(/num2=/, "", $i)

        2. Redefine that column as num2=oldnum-5 - $i="num2="$i-5

        3. Print the line - print





        share|improve this answer
















        Using awk:



        awk ' for (i=1;i<=NF;i++) if ($i ~ /num2=/) sub(/num2=/, "", $i); $i="num2="$i-5; print ' file


        This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:



        1. Remove num2= - sub(/num2=/, "", $i)

        2. Redefine that column as num2=oldnum-5 - $i="num2="$i-5

        3. Print the line - print






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited Oct 16 at 17:05

























        answered Oct 16 at 16:57









        Jesse_bJesse_b

        21.6k3 gold badges51 silver badges93 bronze badges




        21.6k3 gold badges51 silver badges93 bronze badges















        • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

          – TuxForLife
          Oct 16 at 17:01











        • @TuxForLife: I've updated the answer.

          – Jesse_b
          Oct 16 at 17:05






        • 1





          Works like a charm, thanks Jesse

          – TuxForLife
          Oct 16 at 17:10

















        • In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

          – TuxForLife
          Oct 16 at 17:01











        • @TuxForLife: I've updated the answer.

          – Jesse_b
          Oct 16 at 17:05






        • 1





          Works like a charm, thanks Jesse

          – TuxForLife
          Oct 16 at 17:10
















        In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

        – TuxForLife
        Oct 16 at 17:01





        In my scenario, I do believe RANDOM TEXT will be consistently 2 columns, but to play it safe, the consistent tell will be num2=

        – TuxForLife
        Oct 16 at 17:01













        @TuxForLife: I've updated the answer.

        – Jesse_b
        Oct 16 at 17:05





        @TuxForLife: I've updated the answer.

        – Jesse_b
        Oct 16 at 17:05




        1




        1





        Works like a charm, thanks Jesse

        – TuxForLife
        Oct 16 at 17:10





        Works like a charm, thanks Jesse

        – TuxForLife
        Oct 16 at 17:10













        5



















        perl:



        perl -pe 's/(?<=num2=)(d+)/$1 - 5/e' file


        To store the contents back into the file:



        perl -i -pe ...





        share|improve this answer






























          5



















          perl:



          perl -pe 's/(?<=num2=)(d+)/$1 - 5/e' file


          To store the contents back into the file:



          perl -i -pe ...





          share|improve this answer




























            5















            5











            5









            perl:



            perl -pe 's/(?<=num2=)(d+)/$1 - 5/e' file


            To store the contents back into the file:



            perl -i -pe ...





            share|improve this answer














            perl:



            perl -pe 's/(?<=num2=)(d+)/$1 - 5/e' file


            To store the contents back into the file:



            perl -i -pe ...






            share|improve this answer













            share|improve this answer




            share|improve this answer










            answered Oct 16 at 19:40









            glenn jackmanglenn jackman

            58.2k8 gold badges80 silver badges124 bronze badges




            58.2k8 gold badges80 silver badges124 bronze badges
























                4



















                [Just because I'm trying to become more familiar with Miller - it requires some jumping through hoops to get the heterogeneous output]:



                $ mlr --fs ' ' --repifs --ocsvlite --headerless-csv-output put '
                $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                ' file
                RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                RANDOM TEXT num1=200 num2=0 RANDOM TEXT


                If the input is actually TSV in which some columns may contain spaces, then



                $ mlr --fs 't' --ocsvlite --headerless-csv-output put '
                $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                ' file
                RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                RANDOM TEXT num1=200 num2=0 RANDOM TEXT





                share|improve this answer






























                  4



















                  [Just because I'm trying to become more familiar with Miller - it requires some jumping through hoops to get the heterogeneous output]:



                  $ mlr --fs ' ' --repifs --ocsvlite --headerless-csv-output put '
                  $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                  ' file
                  RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                  RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                  RANDOM TEXT num1=200 num2=0 RANDOM TEXT


                  If the input is actually TSV in which some columns may contain spaces, then



                  $ mlr --fs 't' --ocsvlite --headerless-csv-output put '
                  $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                  ' file
                  RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                  RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                  RANDOM TEXT num1=200 num2=0 RANDOM TEXT





                  share|improve this answer




























                    4















                    4











                    4









                    [Just because I'm trying to become more familiar with Miller - it requires some jumping through hoops to get the heterogeneous output]:



                    $ mlr --fs ' ' --repifs --ocsvlite --headerless-csv-output put '
                    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                    ' file
                    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                    RANDOM TEXT num1=200 num2=0 RANDOM TEXT


                    If the input is actually TSV in which some columns may contain spaces, then



                    $ mlr --fs 't' --ocsvlite --headerless-csv-output put '
                    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                    ' file
                    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                    RANDOM TEXT num1=200 num2=0 RANDOM TEXT





                    share|improve this answer














                    [Just because I'm trying to become more familiar with Miller - it requires some jumping through hoops to get the heterogeneous output]:



                    $ mlr --fs ' ' --repifs --ocsvlite --headerless-csv-output put '
                    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                    ' file
                    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                    RANDOM TEXT num1=200 num2=0 RANDOM TEXT


                    If the input is actually TSV in which some columns may contain spaces, then



                    $ mlr --fs 't' --ocsvlite --headerless-csv-output put '
                    $num1 = "num1=".$num1; $num2 = "num2=".($num2-5)
                    ' file
                    RANDOM TEXT num1=400 num2=10 RANDOM TEXT
                    RANDOM TEXT num1=300 num2=5 RANDOM TEXT
                    RANDOM TEXT num1=200 num2=0 RANDOM TEXT






                    share|improve this answer













                    share|improve this answer




                    share|improve this answer










                    answered Oct 16 at 18:09









                    steeldriversteeldriver

                    45.4k7 gold badges59 silver badges98 bronze badges




                    45.4k7 gold badges59 silver badges98 bronze badges
























                        0



















                        Using Vim:



                        vim +'g/^/exe "norm! 3Wf=5<C-A>"' +wq file


                        The first + argument runs a series of normal mode operations on each line to increment the number 5 times. It uses a :global command to run this on every line. Simply using :normal with a range %norm would be simpler if we weren't using CTRLA to increment the number, but in order to (easily) pass this control character into Vim we build the command as a string to run with :execute, and thus we need the :global.



                        The second + argument simply saves the file.



                        If the format of RANDOM TEXT is less regular (or if you just prefer regular expressions), you could instead use a :substitute command:



                        vim +'%s/num2=zsd+/=submatch(0) + 5' +wq file


                        This uses a :substitute command to replace the N part of num2=N with the existing value plus five.






                        share|improve this answer
































                          0



















                          Using Vim:



                          vim +'g/^/exe "norm! 3Wf=5<C-A>"' +wq file


                          The first + argument runs a series of normal mode operations on each line to increment the number 5 times. It uses a :global command to run this on every line. Simply using :normal with a range %norm would be simpler if we weren't using CTRLA to increment the number, but in order to (easily) pass this control character into Vim we build the command as a string to run with :execute, and thus we need the :global.



                          The second + argument simply saves the file.



                          If the format of RANDOM TEXT is less regular (or if you just prefer regular expressions), you could instead use a :substitute command:



                          vim +'%s/num2=zsd+/=submatch(0) + 5' +wq file


                          This uses a :substitute command to replace the N part of num2=N with the existing value plus five.






                          share|improve this answer






























                            0















                            0











                            0









                            Using Vim:



                            vim +'g/^/exe "norm! 3Wf=5<C-A>"' +wq file


                            The first + argument runs a series of normal mode operations on each line to increment the number 5 times. It uses a :global command to run this on every line. Simply using :normal with a range %norm would be simpler if we weren't using CTRLA to increment the number, but in order to (easily) pass this control character into Vim we build the command as a string to run with :execute, and thus we need the :global.



                            The second + argument simply saves the file.



                            If the format of RANDOM TEXT is less regular (or if you just prefer regular expressions), you could instead use a :substitute command:



                            vim +'%s/num2=zsd+/=submatch(0) + 5' +wq file


                            This uses a :substitute command to replace the N part of num2=N with the existing value plus five.






                            share|improve this answer
















                            Using Vim:



                            vim +'g/^/exe "norm! 3Wf=5<C-A>"' +wq file


                            The first + argument runs a series of normal mode operations on each line to increment the number 5 times. It uses a :global command to run this on every line. Simply using :normal with a range %norm would be simpler if we weren't using CTRLA to increment the number, but in order to (easily) pass this control character into Vim we build the command as a string to run with :execute, and thus we need the :global.



                            The second + argument simply saves the file.



                            If the format of RANDOM TEXT is less regular (or if you just prefer regular expressions), you could instead use a :substitute command:



                            vim +'%s/num2=zsd+/=submatch(0) + 5' +wq file


                            This uses a :substitute command to replace the N part of num2=N with the existing value plus five.







                            share|improve this answer















                            share|improve this answer




                            share|improve this answer








                            edited Oct 17 at 14:57

























                            answered Oct 17 at 12:10









                            RichRich

                            1013 bronze badges




                            1013 bronze badges































                                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%2f547119%2fhow-can-i-adjust-nth-number-in-a-line%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

                                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

                                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

                                Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її