Extract a string out of key, value from a text file, and assign to a new variable

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











up vote
0
down vote

favorite












Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").



cat abc.txt

foo_key1=foo.com|/tmp/worker$Build_Number
foo_key2=goo.com|/tmp/manager$Build_Number


I have tried the below code but no luck.



while IFS== read -r key val ; do
val=$val%"; val=$val#"; key=$key#export ;
A="$(cut -d'_' -f1 <<<"$key")"
B="$(cut -d'_' -f1 <<<"$val")"
C="$(cut -d'_' -f2 <<<"$val")"
echo $A
echo $B
echo $C
done < abc.txt


Expected output:



foo_key1 
foo.com
/tmp/worker$Build_Number








share

























    up vote
    0
    down vote

    favorite












    Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").



    cat abc.txt

    foo_key1=foo.com|/tmp/worker$Build_Number
    foo_key2=goo.com|/tmp/manager$Build_Number


    I have tried the below code but no luck.



    while IFS== read -r key val ; do
    val=$val%"; val=$val#"; key=$key#export ;
    A="$(cut -d'_' -f1 <<<"$key")"
    B="$(cut -d'_' -f1 <<<"$val")"
    C="$(cut -d'_' -f2 <<<"$val")"
    echo $A
    echo $B
    echo $C
    done < abc.txt


    Expected output:



    foo_key1 
    foo.com
    /tmp/worker$Build_Number








    share























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").



      cat abc.txt

      foo_key1=foo.com|/tmp/worker$Build_Number
      foo_key2=goo.com|/tmp/manager$Build_Number


      I have tried the below code but no luck.



      while IFS== read -r key val ; do
      val=$val%"; val=$val#"; key=$key#export ;
      A="$(cut -d'_' -f1 <<<"$key")"
      B="$(cut -d'_' -f1 <<<"$val")"
      C="$(cut -d'_' -f2 <<<"$val")"
      echo $A
      echo $B
      echo $C
      done < abc.txt


      Expected output:



      foo_key1 
      foo.com
      /tmp/worker$Build_Number








      share













      Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").



      cat abc.txt

      foo_key1=foo.com|/tmp/worker$Build_Number
      foo_key2=goo.com|/tmp/manager$Build_Number


      I have tried the below code but no luck.



      while IFS== read -r key val ; do
      val=$val%"; val=$val#"; key=$key#export ;
      A="$(cut -d'_' -f1 <<<"$key")"
      B="$(cut -d'_' -f1 <<<"$val")"
      C="$(cut -d'_' -f2 <<<"$val")"
      echo $A
      echo $B
      echo $C
      done < abc.txt


      Expected output:



      foo_key1 
      foo.com
      /tmp/worker$Build_Number






      linux shell regular-expression python





      share












      share










      share



      share










      asked 56 secs ago









      itgeek

      201




      201

























          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',
          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%2f475927%2fextract-a-string-out-of-key-value-from-a-text-file-and-assign-to-a-new-variabl%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475927%2fextract-a-string-out-of-key-value-from-a-text-file-and-assign-to-a-new-variabl%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?

          Christian Cage

          How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?