Bash - How to update what's inside the quotes, but only if it's a number? Announcing the...

How do you clear the ApexPages.getMessages() collection in a test?

Cold is to Refrigerator as warm is to?

Problem when applying foreach loop

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Slither Like a Snake

How do I automatically answer y in bash script?

Statistical model of ligand substitution

If A makes B more likely then B makes A more likely"

Are my PIs rude or am I just being too sensitive?

How should I respond to a player wanting to catch a sword between their hands?

What's the point in a preamp?

What did Darwin mean by 'squib' here?

How to colour the US map with Yellow, Green, Red and Blue to minimize the number of states with the colour of Green

Need a suitable toxic chemical for a murder plot in my novel

Passing functions in C++

Can a zero nonce be safely used with AES-GCM if the key is random and never used again?

Did the new image of black hole confirm the general theory of relativity?

Losing the Initialization Vector in Cipher Block Chaining

Can a monk deflect thrown melee weapons?

I'm thinking of a number

How can I make names more distinctive without making them longer?

Why does tar appear to skip file contents when output file is /dev/null?

Single author papers against my advisor's will?

Stop battery usage [Ubuntu 18]



Bash - How to update what's inside the quotes, but only if it's a number?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” question





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







0















For this project, we have hundreds of applications using composer.json. I'm using a Bash script to go through and update the version numbers of any file that contain an application that is getting a new version.



For example, the original file looks like this (I put in only the relevant parts):



{
"name" : "test/graylogger"
"version" : "1.1.1"
...
"require": {
"test/phpunit": "4.8.23"
}


I want to update it to this:



{
"name" : "test/graylogger"
"version" : "1.1.2"
...
"require": {
"test/phpunit": "4.8.24"
}


But, it is ending up like this (which I don't want):



{
"name" : "1.1.2"
"version" : "1.1.2"
...
"require": {
"test/phpunit": "4.8.24"
}


Basically, my script is supposed to be searching for 'version', updating the second quote after this up by one, and then looping through based on the folder file name (in this case, 'graylogger'), and then upping that in any other folders that contain that application. But for some reason, it's also updating the name, which I don't want. Here is my snippet of code that is doing this:



while read line2; do

line1="$line1"" #I did this to prevent any repetitive names from upping twice
original=$(grep -hr "$line1" /Websites/"$line2"/composer.json | awk -F " '{print $4}')

if [["$original" != *"$line1"*]]; then
sed -i'' s,"original","version",g composer.json

done < websites.txt


line1 is the application that is being updating within the file.



line2 is the file that is being updated.



I tried to make an if statement that excludes the change if the text in the second includes the name of the application, it doesn't update, but it doesn't seem to be working.



This is being done on a Mac.



Thanks!









share







New contributor




Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    For this project, we have hundreds of applications using composer.json. I'm using a Bash script to go through and update the version numbers of any file that contain an application that is getting a new version.



    For example, the original file looks like this (I put in only the relevant parts):



    {
    "name" : "test/graylogger"
    "version" : "1.1.1"
    ...
    "require": {
    "test/phpunit": "4.8.23"
    }


    I want to update it to this:



    {
    "name" : "test/graylogger"
    "version" : "1.1.2"
    ...
    "require": {
    "test/phpunit": "4.8.24"
    }


    But, it is ending up like this (which I don't want):



    {
    "name" : "1.1.2"
    "version" : "1.1.2"
    ...
    "require": {
    "test/phpunit": "4.8.24"
    }


    Basically, my script is supposed to be searching for 'version', updating the second quote after this up by one, and then looping through based on the folder file name (in this case, 'graylogger'), and then upping that in any other folders that contain that application. But for some reason, it's also updating the name, which I don't want. Here is my snippet of code that is doing this:



    while read line2; do

    line1="$line1"" #I did this to prevent any repetitive names from upping twice
    original=$(grep -hr "$line1" /Websites/"$line2"/composer.json | awk -F " '{print $4}')

    if [["$original" != *"$line1"*]]; then
    sed -i'' s,"original","version",g composer.json

    done < websites.txt


    line1 is the application that is being updating within the file.



    line2 is the file that is being updated.



    I tried to make an if statement that excludes the change if the text in the second includes the name of the application, it doesn't update, but it doesn't seem to be working.



    This is being done on a Mac.



    Thanks!









    share







    New contributor




    Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      For this project, we have hundreds of applications using composer.json. I'm using a Bash script to go through and update the version numbers of any file that contain an application that is getting a new version.



      For example, the original file looks like this (I put in only the relevant parts):



      {
      "name" : "test/graylogger"
      "version" : "1.1.1"
      ...
      "require": {
      "test/phpunit": "4.8.23"
      }


      I want to update it to this:



      {
      "name" : "test/graylogger"
      "version" : "1.1.2"
      ...
      "require": {
      "test/phpunit": "4.8.24"
      }


      But, it is ending up like this (which I don't want):



      {
      "name" : "1.1.2"
      "version" : "1.1.2"
      ...
      "require": {
      "test/phpunit": "4.8.24"
      }


      Basically, my script is supposed to be searching for 'version', updating the second quote after this up by one, and then looping through based on the folder file name (in this case, 'graylogger'), and then upping that in any other folders that contain that application. But for some reason, it's also updating the name, which I don't want. Here is my snippet of code that is doing this:



      while read line2; do

      line1="$line1"" #I did this to prevent any repetitive names from upping twice
      original=$(grep -hr "$line1" /Websites/"$line2"/composer.json | awk -F " '{print $4}')

      if [["$original" != *"$line1"*]]; then
      sed -i'' s,"original","version",g composer.json

      done < websites.txt


      line1 is the application that is being updating within the file.



      line2 is the file that is being updated.



      I tried to make an if statement that excludes the change if the text in the second includes the name of the application, it doesn't update, but it doesn't seem to be working.



      This is being done on a Mac.



      Thanks!









      share







      New contributor




      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      For this project, we have hundreds of applications using composer.json. I'm using a Bash script to go through and update the version numbers of any file that contain an application that is getting a new version.



      For example, the original file looks like this (I put in only the relevant parts):



      {
      "name" : "test/graylogger"
      "version" : "1.1.1"
      ...
      "require": {
      "test/phpunit": "4.8.23"
      }


      I want to update it to this:



      {
      "name" : "test/graylogger"
      "version" : "1.1.2"
      ...
      "require": {
      "test/phpunit": "4.8.24"
      }


      But, it is ending up like this (which I don't want):



      {
      "name" : "1.1.2"
      "version" : "1.1.2"
      ...
      "require": {
      "test/phpunit": "4.8.24"
      }


      Basically, my script is supposed to be searching for 'version', updating the second quote after this up by one, and then looping through based on the folder file name (in this case, 'graylogger'), and then upping that in any other folders that contain that application. But for some reason, it's also updating the name, which I don't want. Here is my snippet of code that is doing this:



      while read line2; do

      line1="$line1"" #I did this to prevent any repetitive names from upping twice
      original=$(grep -hr "$line1" /Websites/"$line2"/composer.json | awk -F " '{print $4}')

      if [["$original" != *"$line1"*]]; then
      sed -i'' s,"original","version",g composer.json

      done < websites.txt


      line1 is the application that is being updating within the file.



      line2 is the file that is being updated.



      I tried to make an if statement that excludes the change if the text in the second includes the name of the application, it doesn't update, but it doesn't seem to be working.



      This is being done on a Mac.



      Thanks!







      bash awk sed macintosh





      share







      New contributor




      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      GlitteropiaGlitteropia

      12




      12




      New contributor




      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Glitteropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Glitteropia is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512469%2fbash-how-to-update-whats-inside-the-quotes-but-only-if-its-a-number%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Glitteropia is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Glitteropia is a new contributor. Be nice, and check out our Code of Conduct.













          Glitteropia is a new contributor. Be nice, and check out our Code of Conduct.












          Glitteropia is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f512469%2fbash-how-to-update-whats-inside-the-quotes-but-only-if-its-a-number%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

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

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

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