Add 100 to decimals in Multiple TXT files

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.



sample



"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]






share|improve this question

















  • 3




    post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
    – RomanPerekhrest
    May 8 at 7:12











  • It's in a single line, and doesn't stand therefore as a separate line.
    – PJ547
    May 8 at 7:19






  • 1




    A full example would still be good.
    – Kusalananda
    May 8 at 7:24






  • 2




    Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
    – roaima
    May 8 at 7:36







  • 1




    Also specify whether there could be multiple entries "moves":<number>, on the same line
    – RomanPerekhrest
    May 8 at 7:39














up vote
0
down vote

favorite












I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.



sample



"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]






share|improve this question

















  • 3




    post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
    – RomanPerekhrest
    May 8 at 7:12











  • It's in a single line, and doesn't stand therefore as a separate line.
    – PJ547
    May 8 at 7:19






  • 1




    A full example would still be good.
    – Kusalananda
    May 8 at 7:24






  • 2




    Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
    – roaima
    May 8 at 7:36







  • 1




    Also specify whether there could be multiple entries "moves":<number>, on the same line
    – RomanPerekhrest
    May 8 at 7:39












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.



sample



"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]






share|improve this question













I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). So how do I add 100 to all the moves decimal in multiple files and save them. The moves is not 30, it's random number in every text files. And they all are between 10-999.



sample



"gameModeName":"Classic moves","moveLimit":106,"numberOfColours":6,"portals":,"protocolVersion":"0.3","randomConfig":"mode":"Seed Pool","modeModifier":"Tutorial Only","overrideAbTest":true,"seedPool":[547787],"randomSeed":1088126,"scoreTargets":[300,400,500],"tileMap":[["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"],["002005","002005","002005","002005","002005","002005","002005","002005","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["002","002","002","002","002","002","002","002","000"],["000","000","000","000","000","000","000","000","000"],["000","000","000","000","000","000","000","000","000"]]








share|improve this question












share|improve this question




share|improve this question








edited May 9 at 9:39









Jeff Schaller

31.1k846105




31.1k846105









asked May 8 at 7:10









PJ547

91




91







  • 3




    post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
    – RomanPerekhrest
    May 8 at 7:12











  • It's in a single line, and doesn't stand therefore as a separate line.
    – PJ547
    May 8 at 7:19






  • 1




    A full example would still be good.
    – Kusalananda
    May 8 at 7:24






  • 2




    Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
    – roaima
    May 8 at 7:36







  • 1




    Also specify whether there could be multiple entries "moves":<number>, on the same line
    – RomanPerekhrest
    May 8 at 7:39












  • 3




    post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
    – RomanPerekhrest
    May 8 at 7:12











  • It's in a single line, and doesn't stand therefore as a separate line.
    – PJ547
    May 8 at 7:19






  • 1




    A full example would still be good.
    – Kusalananda
    May 8 at 7:24






  • 2




    Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
    – roaima
    May 8 at 7:36







  • 1




    Also specify whether there could be multiple entries "moves":<number>, on the same line
    – RomanPerekhrest
    May 8 at 7:39







3




3




post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
– RomanPerekhrest
May 8 at 7:12





post a testable file's content (we need to see whether "moves":30, is a part of the line or stands as a separate line)
– RomanPerekhrest
May 8 at 7:12













It's in a single line, and doesn't stand therefore as a separate line.
– PJ547
May 8 at 7:19




It's in a single line, and doesn't stand therefore as a separate line.
– PJ547
May 8 at 7:19




1




1




A full example would still be good.
– Kusalananda
May 8 at 7:24




A full example would still be good.
– Kusalananda
May 8 at 7:24




2




2




Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
– roaima
May 8 at 7:36





Instead of uploading to pastebin, please put a sample here in the question. AND a sample of the corresponding expected output Just 4 or 5 lines will be sufficient. (Paste it here, select the lines, use on the formatting bar to mark it as code.) A question should ideally be complete in itself.
– roaima
May 8 at 7:36





1




1




Also specify whether there could be multiple entries "moves":<number>, on the same line
– RomanPerekhrest
May 8 at 7:39




Also specify whether there could be multiple entries "moves":<number>, on the same line
– RomanPerekhrest
May 8 at 7:39










2 Answers
2






active

oldest

votes

















up vote
5
down vote













If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.



Use a proper JSON tools like jq as this would be the right way:



for f in *.txt; do
if grep -q '"moveLimit":[0-9]*,' "$f"; then
jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
fi
done





share|improve this answer





















  • This worked ! Thanks a lot.
    – PJ547
    May 8 at 8:26










  • @PJ547, you're welcome
    – RomanPerekhrest
    May 8 at 9:06






  • 2




    @PJ547 Good! If this solves your issue, please consider accepting the answer.
    – Kusalananda
    May 8 at 10:12

















up vote
1
down vote













On a GNU or FreeBSD system, you could try something like:



grep -rl --null '"moveLimit":[0-9]' . |
xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'



  • grep recursively lists the files in the current directory (.) that contain "moveLimit": followed by a decimal digit (null-delimited for xargs -0)


  • xargs -r0 passes that list of files to perl


  • perl edits the files in-place and replaces sequences of digits (d+ that follow "moveLimit": with the same number ($&) plus 100.





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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f442475%2fadd-100-to-decimals-in-multiple-txt-files%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.



    Use a proper JSON tools like jq as this would be the right way:



    for f in *.txt; do
    if grep -q '"moveLimit":[0-9]*,' "$f"; then
    jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
    fi
    done





    share|improve this answer





















    • This worked ! Thanks a lot.
      – PJ547
      May 8 at 8:26










    • @PJ547, you're welcome
      – RomanPerekhrest
      May 8 at 9:06






    • 2




      @PJ547 Good! If this solves your issue, please consider accepting the answer.
      – Kusalananda
      May 8 at 10:12














    up vote
    5
    down vote













    If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.



    Use a proper JSON tools like jq as this would be the right way:



    for f in *.txt; do
    if grep -q '"moveLimit":[0-9]*,' "$f"; then
    jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
    fi
    done





    share|improve this answer





















    • This worked ! Thanks a lot.
      – PJ547
      May 8 at 8:26










    • @PJ547, you're welcome
      – RomanPerekhrest
      May 8 at 9:06






    • 2




      @PJ547 Good! If this solves your issue, please consider accepting the answer.
      – Kusalananda
      May 8 at 10:12












    up vote
    5
    down vote










    up vote
    5
    down vote









    If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.



    Use a proper JSON tools like jq as this would be the right way:



    for f in *.txt; do
    if grep -q '"moveLimit":[0-9]*,' "$f"; then
    jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
    fi
    done





    share|improve this answer













    If you would say at the very start that your txt files are actually JSON files (as your sample just looks like) - it would have changed everything and prevent most of the questions/comments.



    Use a proper JSON tools like jq as this would be the right way:



    for f in *.txt; do
    if grep -q '"moveLimit":[0-9]*,' "$f"; then
    jq -c '.moveLimit |= . + 100' "$f" > tmp_f && mv tmp_f "$f"
    fi
    done






    share|improve this answer













    share|improve this answer



    share|improve this answer











    answered May 8 at 8:06









    RomanPerekhrest

    22.4k12144




    22.4k12144











    • This worked ! Thanks a lot.
      – PJ547
      May 8 at 8:26










    • @PJ547, you're welcome
      – RomanPerekhrest
      May 8 at 9:06






    • 2




      @PJ547 Good! If this solves your issue, please consider accepting the answer.
      – Kusalananda
      May 8 at 10:12
















    • This worked ! Thanks a lot.
      – PJ547
      May 8 at 8:26










    • @PJ547, you're welcome
      – RomanPerekhrest
      May 8 at 9:06






    • 2




      @PJ547 Good! If this solves your issue, please consider accepting the answer.
      – Kusalananda
      May 8 at 10:12















    This worked ! Thanks a lot.
    – PJ547
    May 8 at 8:26




    This worked ! Thanks a lot.
    – PJ547
    May 8 at 8:26












    @PJ547, you're welcome
    – RomanPerekhrest
    May 8 at 9:06




    @PJ547, you're welcome
    – RomanPerekhrest
    May 8 at 9:06




    2




    2




    @PJ547 Good! If this solves your issue, please consider accepting the answer.
    – Kusalananda
    May 8 at 10:12




    @PJ547 Good! If this solves your issue, please consider accepting the answer.
    – Kusalananda
    May 8 at 10:12












    up vote
    1
    down vote













    On a GNU or FreeBSD system, you could try something like:



    grep -rl --null '"moveLimit":[0-9]' . |
    xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'



    • grep recursively lists the files in the current directory (.) that contain "moveLimit": followed by a decimal digit (null-delimited for xargs -0)


    • xargs -r0 passes that list of files to perl


    • perl edits the files in-place and replaces sequences of digits (d+ that follow "moveLimit": with the same number ($&) plus 100.





    share|improve this answer



























      up vote
      1
      down vote













      On a GNU or FreeBSD system, you could try something like:



      grep -rl --null '"moveLimit":[0-9]' . |
      xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'



      • grep recursively lists the files in the current directory (.) that contain "moveLimit": followed by a decimal digit (null-delimited for xargs -0)


      • xargs -r0 passes that list of files to perl


      • perl edits the files in-place and replaces sequences of digits (d+ that follow "moveLimit": with the same number ($&) plus 100.





      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        On a GNU or FreeBSD system, you could try something like:



        grep -rl --null '"moveLimit":[0-9]' . |
        xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'



        • grep recursively lists the files in the current directory (.) that contain "moveLimit": followed by a decimal digit (null-delimited for xargs -0)


        • xargs -r0 passes that list of files to perl


        • perl edits the files in-place and replaces sequences of digits (d+ that follow "moveLimit": with the same number ($&) plus 100.





        share|improve this answer















        On a GNU or FreeBSD system, you could try something like:



        grep -rl --null '"moveLimit":[0-9]' . |
        xargs -r0 perl -pi -e 's/"moveLimit":Kd+/$& + 100/ge'



        • grep recursively lists the files in the current directory (.) that contain "moveLimit": followed by a decimal digit (null-delimited for xargs -0)


        • xargs -r0 passes that list of files to perl


        • perl edits the files in-place and replaces sequences of digits (d+ that follow "moveLimit": with the same number ($&) plus 100.






        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited May 8 at 8:57


























        answered May 8 at 8:05









        Stéphane Chazelas

        279k53514845




        279k53514845






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442475%2fadd-100-to-decimals-in-multiple-txt-files%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay