How to use awk to find and replace with calculation? [duplicate]

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











up vote
5
down vote

favorite













This question already has an answer here:



  • Bash script Multiply only numbers from a text file?

    4 answers



I have several CSS files under a folder contains 0.2rem or 0.5rem 0.6rem, now I want them to be all divided by 2, become 0.1rem and 0.25rem, 0.3rem. How can I use awk or sed or gawk to accomplish this?



I tried the following command but have no success:



find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'






share|improve this question














marked as duplicate by αғsнιη, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    5
    down vote

    favorite













    This question already has an answer here:



    • Bash script Multiply only numbers from a text file?

      4 answers



    I have several CSS files under a folder contains 0.2rem or 0.5rem 0.6rem, now I want them to be all divided by 2, become 0.1rem and 0.25rem, 0.3rem. How can I use awk or sed or gawk to accomplish this?



    I tried the following command but have no success:



    find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'






    share|improve this question














    marked as duplicate by αғsнιη, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite












      This question already has an answer here:



      • Bash script Multiply only numbers from a text file?

        4 answers



      I have several CSS files under a folder contains 0.2rem or 0.5rem 0.6rem, now I want them to be all divided by 2, become 0.1rem and 0.25rem, 0.3rem. How can I use awk or sed or gawk to accomplish this?



      I tried the following command but have no success:



      find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'






      share|improve this question















      This question already has an answer here:



      • Bash script Multiply only numbers from a text file?

        4 answers



      I have several CSS files under a folder contains 0.2rem or 0.5rem 0.6rem, now I want them to be all divided by 2, become 0.1rem and 0.25rem, 0.3rem. How can I use awk or sed or gawk to accomplish this?



      I tried the following command but have no success:



      find . -name "*.css" | xargs gawk -i inplace 'gsub(/([0-9.]+)rem/, "(\1 * 0.5)rem"); print $0'




      This question already has an answer here:



      • Bash script Multiply only numbers from a text file?

        4 answers









      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 14 at 10:07









      David Foerster

      915616




      915616










      asked Mar 14 at 6:48









      Zhang Buzz

      1284




      1284




      marked as duplicate by αғsнιη, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by αғsнιη, Kiwy, Jeff Schaller, elbarna, G-Man Mar 15 at 2:03


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          find + GNU awk solution:



          find . -type f -name "*.css" -exec gawk -i inplace 
          ' for (i=1; i<=NF; i++)
          if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
          1' ;





          share|improve this answer






















          • Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
            – Zhang Buzz
            Mar 14 at 7:28










          • @ZhangBuzz, you did not mention that in your question. Anyway, see my update
            – RomanPerekhrest
            Mar 14 at 7:37










          • I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
            – Zhang Buzz
            Mar 14 at 7:58

















          up vote
          7
          down vote













          Not sure about sed/gawk, but here's one with perl



          $ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
          0.1rem or 0.25rem 0.3rem



          • d+(.d+)? match digits with optional fractional part


            • (?=rem) to ensure the number is followed by rem



          • $&*0.5 multiply the number by 0.5 - the e modifier allows to use Perl code instead of string in replacement section



          Applying to files:



          find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +


          See also: Why is looping over find's output bad practice?






          share|improve this answer




















          • That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
            – Sparhawk
            Mar 14 at 22:13










          • @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
            – Sundeep
            Mar 15 at 3:13






          • 1




            Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
            – Sparhawk
            Mar 15 at 3:17

















          up vote
          4
          down vote













          With gawk, you could use RS that is treated as a regexp there and the fact that there, RT contains what was matched by RS. So:



          find . -name '*.css' -type f -exec 
          gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +





          share|improve this answer





























            up vote
            1
            down vote













            gawk -i inplace '

            for(i = 1; i <= NF; i++)
            if($i ~ /[0-9]+(.[0-9]+)?rem/)
            $i = $i / 2 "rem"

            print
            ' file_*


            The 3 files content before the program execution



            The tail -n +1 -- file_* command shows the multiple files content at once.



            $ tail -n +1 -- file_*

            ==> file_1 <==
            0.2rem lorem ipsum 0.5rem
            Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
            Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
            0.2rem lorem ipsum 0.5rem

            ==> file_2 <==
            0.2rem lorem ipsum 0.5rem
            Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
            0.2rem lorem ipsum 0.5rem
            Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.

            ==> file_3 <==
            0.2rem lorem ipsum 0.5rem
            Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
            Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.


            The 3 files content after the program execution



            $ tail -n +1 -- file_*

            ==> file_1 <==
            0.1rem lorem ipsum 0.25rem
            Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
            Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
            0.1rem lorem ipsum 0.25rem

            ==> file_2 <==
            0.1rem lorem ipsum 0.25rem
            Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
            0.1rem lorem ipsum 0.25rem
            Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.

            ==> file_3 <==
            0.1rem lorem ipsum 0.25rem
            Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
            Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.





            share|improve this answer





























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote



              accepted










              find + GNU awk solution:



              find . -type f -name "*.css" -exec gawk -i inplace 
              ' for (i=1; i<=NF; i++)
              if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
              1' ;





              share|improve this answer






















              • Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
                – Zhang Buzz
                Mar 14 at 7:28










              • @ZhangBuzz, you did not mention that in your question. Anyway, see my update
                – RomanPerekhrest
                Mar 14 at 7:37










              • I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
                – Zhang Buzz
                Mar 14 at 7:58














              up vote
              5
              down vote



              accepted










              find + GNU awk solution:



              find . -type f -name "*.css" -exec gawk -i inplace 
              ' for (i=1; i<=NF; i++)
              if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
              1' ;





              share|improve this answer






















              • Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
                – Zhang Buzz
                Mar 14 at 7:28










              • @ZhangBuzz, you did not mention that in your question. Anyway, see my update
                – RomanPerekhrest
                Mar 14 at 7:37










              • I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
                – Zhang Buzz
                Mar 14 at 7:58












              up vote
              5
              down vote



              accepted







              up vote
              5
              down vote



              accepted






              find + GNU awk solution:



              find . -type f -name "*.css" -exec gawk -i inplace 
              ' for (i=1; i<=NF; i++)
              if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
              1' ;





              share|improve this answer














              find + GNU awk solution:



              find . -type f -name "*.css" -exec gawk -i inplace 
              ' for (i=1; i<=NF; i++)
              if ($i ~ /^[0-9]+.[0-9]+rem/) v=$i/2; sub(/^[0-9]+.[0-9]+/, "", $i); $i=v $i
              1' ;






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 14 at 7:36

























              answered Mar 14 at 7:00









              RomanPerekhrest

              22.4k12144




              22.4k12144











              • Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
                – Zhang Buzz
                Mar 14 at 7:28










              • @ZhangBuzz, you did not mention that in your question. Anyway, see my update
                – RomanPerekhrest
                Mar 14 at 7:37










              • I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
                – Zhang Buzz
                Mar 14 at 7:58
















              • Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
                – Zhang Buzz
                Mar 14 at 7:28










              • @ZhangBuzz, you did not mention that in your question. Anyway, see my update
                – RomanPerekhrest
                Mar 14 at 7:37










              • I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
                – Zhang Buzz
                Mar 14 at 7:58















              Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
              – Zhang Buzz
              Mar 14 at 7:28




              Thank you! I tried with some change: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9].[0-9]rem/) sub("rem", "", $i); $i = $i * 0.4"rem" 1', everything works fine, just the ; is striped on every line. For example, padding-bottom: 2rem; becomes padding-bottom: 1rem after change. Do you know why?
              – Zhang Buzz
              Mar 14 at 7:28












              @ZhangBuzz, you did not mention that in your question. Anyway, see my update
              – RomanPerekhrest
              Mar 14 at 7:37




              @ZhangBuzz, you did not mention that in your question. Anyway, see my update
              – RomanPerekhrest
              Mar 14 at 7:37












              I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
              – Zhang Buzz
              Mar 14 at 7:58




              I got it! The final command I use is as this: find . -name "*.css" | xargs gawk -i inplace ' for (i=1; i<=NF; i++) if ($i ~ /[0-9]+.[0-9]+rem/) v=$i/2; sub(/[0-9]+.[0-9]+/, "", $i); $i=v $i 1'
              – Zhang Buzz
              Mar 14 at 7:58












              up vote
              7
              down vote













              Not sure about sed/gawk, but here's one with perl



              $ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
              0.1rem or 0.25rem 0.3rem



              • d+(.d+)? match digits with optional fractional part


                • (?=rem) to ensure the number is followed by rem



              • $&*0.5 multiply the number by 0.5 - the e modifier allows to use Perl code instead of string in replacement section



              Applying to files:



              find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +


              See also: Why is looping over find's output bad practice?






              share|improve this answer




















              • That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
                – Sparhawk
                Mar 14 at 22:13










              • @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
                – Sundeep
                Mar 15 at 3:13






              • 1




                Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
                – Sparhawk
                Mar 15 at 3:17














              up vote
              7
              down vote













              Not sure about sed/gawk, but here's one with perl



              $ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
              0.1rem or 0.25rem 0.3rem



              • d+(.d+)? match digits with optional fractional part


                • (?=rem) to ensure the number is followed by rem



              • $&*0.5 multiply the number by 0.5 - the e modifier allows to use Perl code instead of string in replacement section



              Applying to files:



              find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +


              See also: Why is looping over find's output bad practice?






              share|improve this answer




















              • That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
                – Sparhawk
                Mar 14 at 22:13










              • @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
                – Sundeep
                Mar 15 at 3:13






              • 1




                Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
                – Sparhawk
                Mar 15 at 3:17












              up vote
              7
              down vote










              up vote
              7
              down vote









              Not sure about sed/gawk, but here's one with perl



              $ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
              0.1rem or 0.25rem 0.3rem



              • d+(.d+)? match digits with optional fractional part


                • (?=rem) to ensure the number is followed by rem



              • $&*0.5 multiply the number by 0.5 - the e modifier allows to use Perl code instead of string in replacement section



              Applying to files:



              find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +


              See also: Why is looping over find's output bad practice?






              share|improve this answer












              Not sure about sed/gawk, but here's one with perl



              $ echo '0.2rem or 0.5rem 0.6rem' | perl -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge'
              0.1rem or 0.25rem 0.3rem



              • d+(.d+)? match digits with optional fractional part


                • (?=rem) to ensure the number is followed by rem



              • $&*0.5 multiply the number by 0.5 - the e modifier allows to use Perl code instead of string in replacement section



              Applying to files:



              find . -name "*.css" -exec perl -i -pe 's/d+(.d+)?(?=rem)/$&*0.5/ge' +


              See also: Why is looping over find's output bad practice?







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 14 at 6:58









              Sundeep

              6,9511826




              6,9511826











              • That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
                – Sparhawk
                Mar 14 at 22:13










              • @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
                – Sundeep
                Mar 15 at 3:13






              • 1




                Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
                – Sparhawk
                Mar 15 at 3:17
















              • That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
                – Sparhawk
                Mar 14 at 22:13










              • @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
                – Sundeep
                Mar 15 at 3:13






              • 1




                Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
                – Sparhawk
                Mar 15 at 3:17















              That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
              – Sparhawk
              Mar 14 at 22:13




              That link is about looping over the output of find (e.g. for i in $(find…)), not using find's internal loop (-exec or -execdir).
              – Sparhawk
              Mar 14 at 22:13












              @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
              – Sundeep
              Mar 15 at 3:13




              @Sparhawk but the answers cover that aspect... and has a quote that I like very much... find's business is evaluating expressions -- not locating files. Yes, find certainly locates files; but that's really just a side effect.
              – Sundeep
              Mar 15 at 3:13




              1




              1




              Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
              – Sparhawk
              Mar 15 at 3:17




              Ah okay, yes I see mention of that now. I didn't look so deep before. Still, I'm not sure that there's a better solution for your example code.
              – Sparhawk
              Mar 15 at 3:17










              up vote
              4
              down vote













              With gawk, you could use RS that is treated as a regexp there and the fact that there, RT contains what was matched by RS. So:



              find . -name '*.css' -type f -exec 
              gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +





              share|improve this answer


























                up vote
                4
                down vote













                With gawk, you could use RS that is treated as a regexp there and the fact that there, RT contains what was matched by RS. So:



                find . -name '*.css' -type f -exec 
                gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +





                share|improve this answer
























                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  With gawk, you could use RS that is treated as a regexp there and the fact that there, RT contains what was matched by RS. So:



                  find . -name '*.css' -type f -exec 
                  gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +





                  share|improve this answer














                  With gawk, you could use RS that is treated as a regexp there and the fact that there, RT contains what was matched by RS. So:



                  find . -name '*.css' -type f -exec 
                  gawk -i inplace -v RS='[0-9.]*[0-9]rem' -v ORS= 'RT$0=$0 RT/2 "rem";1' +






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 22 at 14:11









                  MiniMax

                  2,681718




                  2,681718










                  answered Mar 14 at 22:09









                  Stéphane Chazelas

                  280k53515847




                  280k53515847




















                      up vote
                      1
                      down vote













                      gawk -i inplace '

                      for(i = 1; i <= NF; i++)
                      if($i ~ /[0-9]+(.[0-9]+)?rem/)
                      $i = $i / 2 "rem"

                      print
                      ' file_*


                      The 3 files content before the program execution



                      The tail -n +1 -- file_* command shows the multiple files content at once.



                      $ tail -n +1 -- file_*

                      ==> file_1 <==
                      0.2rem lorem ipsum 0.5rem
                      Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                      Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
                      0.2rem lorem ipsum 0.5rem

                      ==> file_2 <==
                      0.2rem lorem ipsum 0.5rem
                      Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                      0.2rem lorem ipsum 0.5rem
                      Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.

                      ==> file_3 <==
                      0.2rem lorem ipsum 0.5rem
                      Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                      Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.


                      The 3 files content after the program execution



                      $ tail -n +1 -- file_*

                      ==> file_1 <==
                      0.1rem lorem ipsum 0.25rem
                      Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                      Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
                      0.1rem lorem ipsum 0.25rem

                      ==> file_2 <==
                      0.1rem lorem ipsum 0.25rem
                      Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                      0.1rem lorem ipsum 0.25rem
                      Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.

                      ==> file_3 <==
                      0.1rem lorem ipsum 0.25rem
                      Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                      Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.





                      share|improve this answer


























                        up vote
                        1
                        down vote













                        gawk -i inplace '

                        for(i = 1; i <= NF; i++)
                        if($i ~ /[0-9]+(.[0-9]+)?rem/)
                        $i = $i / 2 "rem"

                        print
                        ' file_*


                        The 3 files content before the program execution



                        The tail -n +1 -- file_* command shows the multiple files content at once.



                        $ tail -n +1 -- file_*

                        ==> file_1 <==
                        0.2rem lorem ipsum 0.5rem
                        Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                        Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
                        0.2rem lorem ipsum 0.5rem

                        ==> file_2 <==
                        0.2rem lorem ipsum 0.5rem
                        Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                        0.2rem lorem ipsum 0.5rem
                        Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.

                        ==> file_3 <==
                        0.2rem lorem ipsum 0.5rem
                        Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                        Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.


                        The 3 files content after the program execution



                        $ tail -n +1 -- file_*

                        ==> file_1 <==
                        0.1rem lorem ipsum 0.25rem
                        Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                        Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
                        0.1rem lorem ipsum 0.25rem

                        ==> file_2 <==
                        0.1rem lorem ipsum 0.25rem
                        Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                        0.1rem lorem ipsum 0.25rem
                        Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.

                        ==> file_3 <==
                        0.1rem lorem ipsum 0.25rem
                        Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                        Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.





                        share|improve this answer
























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          gawk -i inplace '

                          for(i = 1; i <= NF; i++)
                          if($i ~ /[0-9]+(.[0-9]+)?rem/)
                          $i = $i / 2 "rem"

                          print
                          ' file_*


                          The 3 files content before the program execution



                          The tail -n +1 -- file_* command shows the multiple files content at once.



                          $ tail -n +1 -- file_*

                          ==> file_1 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
                          0.2rem lorem ipsum 0.5rem

                          ==> file_2 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          0.2rem lorem ipsum 0.5rem
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.

                          ==> file_3 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.


                          The 3 files content after the program execution



                          $ tail -n +1 -- file_*

                          ==> file_1 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
                          0.1rem lorem ipsum 0.25rem

                          ==> file_2 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          0.1rem lorem ipsum 0.25rem
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.

                          ==> file_3 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.





                          share|improve this answer














                          gawk -i inplace '

                          for(i = 1; i <= NF; i++)
                          if($i ~ /[0-9]+(.[0-9]+)?rem/)
                          $i = $i / 2 "rem"

                          print
                          ' file_*


                          The 3 files content before the program execution



                          The tail -n +1 -- file_* command shows the multiple files content at once.



                          $ tail -n +1 -- file_*

                          ==> file_1 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.
                          0.2rem lorem ipsum 0.5rem

                          ==> file_2 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          0.2rem lorem ipsum 0.5rem
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.

                          ==> file_3 <==
                          0.2rem lorem ipsum 0.5rem
                          Lorem 0.2rem ipsum dolor sit amet, 0.5rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.8rem dolor sit amet, 6rem consectetur 2rem adipiscing elit magna aliqua.


                          The 3 files content after the program execution



                          $ tail -n +1 -- file_*

                          ==> file_1 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.
                          0.1rem lorem ipsum 0.25rem

                          ==> file_2 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          0.1rem lorem ipsum 0.25rem
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.

                          ==> file_3 <==
                          0.1rem lorem ipsum 0.25rem
                          Lorem 0.1rem ipsum dolor sit amet, 0.25rem consectetur adipiscing elit magna aliqua.
                          Lorem ipsum 0.4rem dolor sit amet, 3rem consectetur 1rem adipiscing elit magna aliqua.






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 14 at 21:08

























                          answered Mar 14 at 21:03









                          MiniMax

                          2,681718




                          2,681718












                              Popular posts from this blog

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

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?