Need to read a file and use results as command line arguments in a shell scrip

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











up vote
1
down vote

favorite












I have the following output file from a venn program.



[1, 2],106
[1, 3],2556
[2, 3],5207
[1, 2, 3],232
[2],7566
[3],8840
[1],5320


I need a command to get each line result number as variable argument in a script like this:



$area1=here it must come the results after [1],
$area2=here it must come the results after [2],
$area3=here it must come the results after [3],
$n12=here it must come the results after [1, 2],
$n13=here it must come the results after [1, 3],
$n23=here it must come the results after [2, 3],
$n123=here it must come the results after [1, 2, 3],



these results will then be used in the script below to draw a venn diagram.



cat << catfile >> $prefix1-VennDiagram.R
library(VennDiagram);
venn.diagram(
x = list(
"$sample1" = c(1:$area1, $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13))),
"$sample2" = c($(($area1+$n12+$n123+$n13+1)):$(($area1+$n12+$n123+$n13+$area2)), $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23))),
"$sample3" = c($(($area1+$n12+$n123+$n13+$area2+$n23+1)):$(($area1+$n12+$n123+$n13+$area2+$n23+$area3)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23)))
),
filename = "$prefix1-VennDiagram.tiff",
col = "transparent",
fill = c("red", "blue", "green"),
alpha = 0.5,
label.col = c("darkred", "white", "darkblue", "white", "white", "white", "darkgreen"),
cex = 2.5,
fontfamily = "arial",
fontface = "bold",
cat.default.pos = "text",
cat.col = c("darkred", "darkblue", "darkgreen"),
cat.cex = 2.0,
cat.fontfamily = "arial",
cat.fontface = "italic",
cat.dist = c(0.06, 0.06, 0.03),
cat.pos = 0
);
catfile

Rscript $prefix1-VennDiagram.R
exit


Any help?



Thanks







share|improve this question


























    up vote
    1
    down vote

    favorite












    I have the following output file from a venn program.



    [1, 2],106
    [1, 3],2556
    [2, 3],5207
    [1, 2, 3],232
    [2],7566
    [3],8840
    [1],5320


    I need a command to get each line result number as variable argument in a script like this:



    $area1=here it must come the results after [1],
    $area2=here it must come the results after [2],
    $area3=here it must come the results after [3],
    $n12=here it must come the results after [1, 2],
    $n13=here it must come the results after [1, 3],
    $n23=here it must come the results after [2, 3],
    $n123=here it must come the results after [1, 2, 3],



    these results will then be used in the script below to draw a venn diagram.



    cat << catfile >> $prefix1-VennDiagram.R
    library(VennDiagram);
    venn.diagram(
    x = list(
    "$sample1" = c(1:$area1, $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13))),
    "$sample2" = c($(($area1+$n12+$n123+$n13+1)):$(($area1+$n12+$n123+$n13+$area2)), $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23))),
    "$sample3" = c($(($area1+$n12+$n123+$n13+$area2+$n23+1)):$(($area1+$n12+$n123+$n13+$area2+$n23+$area3)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23)))
    ),
    filename = "$prefix1-VennDiagram.tiff",
    col = "transparent",
    fill = c("red", "blue", "green"),
    alpha = 0.5,
    label.col = c("darkred", "white", "darkblue", "white", "white", "white", "darkgreen"),
    cex = 2.5,
    fontfamily = "arial",
    fontface = "bold",
    cat.default.pos = "text",
    cat.col = c("darkred", "darkblue", "darkgreen"),
    cat.cex = 2.0,
    cat.fontfamily = "arial",
    cat.fontface = "italic",
    cat.dist = c(0.06, 0.06, 0.03),
    cat.pos = 0
    );
    catfile

    Rscript $prefix1-VennDiagram.R
    exit


    Any help?



    Thanks







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have the following output file from a venn program.



      [1, 2],106
      [1, 3],2556
      [2, 3],5207
      [1, 2, 3],232
      [2],7566
      [3],8840
      [1],5320


      I need a command to get each line result number as variable argument in a script like this:



      $area1=here it must come the results after [1],
      $area2=here it must come the results after [2],
      $area3=here it must come the results after [3],
      $n12=here it must come the results after [1, 2],
      $n13=here it must come the results after [1, 3],
      $n23=here it must come the results after [2, 3],
      $n123=here it must come the results after [1, 2, 3],



      these results will then be used in the script below to draw a venn diagram.



      cat << catfile >> $prefix1-VennDiagram.R
      library(VennDiagram);
      venn.diagram(
      x = list(
      "$sample1" = c(1:$area1, $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13))),
      "$sample2" = c($(($area1+$n12+$n123+$n13+1)):$(($area1+$n12+$n123+$n13+$area2)), $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23))),
      "$sample3" = c($(($area1+$n12+$n123+$n13+$area2+$n23+1)):$(($area1+$n12+$n123+$n13+$area2+$n23+$area3)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23)))
      ),
      filename = "$prefix1-VennDiagram.tiff",
      col = "transparent",
      fill = c("red", "blue", "green"),
      alpha = 0.5,
      label.col = c("darkred", "white", "darkblue", "white", "white", "white", "darkgreen"),
      cex = 2.5,
      fontfamily = "arial",
      fontface = "bold",
      cat.default.pos = "text",
      cat.col = c("darkred", "darkblue", "darkgreen"),
      cat.cex = 2.0,
      cat.fontfamily = "arial",
      cat.fontface = "italic",
      cat.dist = c(0.06, 0.06, 0.03),
      cat.pos = 0
      );
      catfile

      Rscript $prefix1-VennDiagram.R
      exit


      Any help?



      Thanks







      share|improve this question














      I have the following output file from a venn program.



      [1, 2],106
      [1, 3],2556
      [2, 3],5207
      [1, 2, 3],232
      [2],7566
      [3],8840
      [1],5320


      I need a command to get each line result number as variable argument in a script like this:



      $area1=here it must come the results after [1],
      $area2=here it must come the results after [2],
      $area3=here it must come the results after [3],
      $n12=here it must come the results after [1, 2],
      $n13=here it must come the results after [1, 3],
      $n23=here it must come the results after [2, 3],
      $n123=here it must come the results after [1, 2, 3],



      these results will then be used in the script below to draw a venn diagram.



      cat << catfile >> $prefix1-VennDiagram.R
      library(VennDiagram);
      venn.diagram(
      x = list(
      "$sample1" = c(1:$area1, $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13))),
      "$sample2" = c($(($area1+$n12+$n123+$n13+1)):$(($area1+$n12+$n123+$n13+$area2)), $(($area1+1)):$(($area1+$n12)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23))),
      "$sample3" = c($(($area1+$n12+$n123+$n13+$area2+$n23+1)):$(($area1+$n12+$n123+$n13+$area2+$n23+$area3)), $(($area1+$n12+1)):$(($area1+$n12+$n123)), $(($area1+$n12+$n123+1)):$(($area1+$n12+$n123+$n13)), $(($area1+$n12+$n123+$n13+$area2+1)):$(($area1+$n12+$n123+$n13+$area2+$n23)))
      ),
      filename = "$prefix1-VennDiagram.tiff",
      col = "transparent",
      fill = c("red", "blue", "green"),
      alpha = 0.5,
      label.col = c("darkred", "white", "darkblue", "white", "white", "white", "darkgreen"),
      cex = 2.5,
      fontfamily = "arial",
      fontface = "bold",
      cat.default.pos = "text",
      cat.col = c("darkred", "darkblue", "darkgreen"),
      cat.cex = 2.0,
      cat.fontfamily = "arial",
      cat.fontface = "italic",
      cat.dist = c(0.06, 0.06, 0.03),
      cat.pos = 0
      );
      catfile

      Rscript $prefix1-VennDiagram.R
      exit


      Any help?



      Thanks









      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 8 '17 at 5:58

























      asked Dec 7 '17 at 2:43









      André Marques

      62




      62




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          Here is a one liner:



          sed 's/^.*],/ /' yourfile|tr -d 'n'|sed -e '$a'


          If you are passing this thing as options to a command you may remove the last sed and use



          sed 's/^.*],/ /' yourfile|tr -d 'n'





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:13











          • Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
            – Weijun Zhou
            Dec 7 '17 at 15:03

















          up vote
          1
          down vote













          You could use awk to print the last comma-separated field of each line, and then (provided the argument list does not exceed its limits) xargs to assemble them into a single line:



          $ awk -F, 'print $NF' yourfile | xargs
          106 2556 5207 232 7566 8840 5320





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:17










          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%2f409360%2fneed-to-read-a-file-and-use-results-as-command-line-arguments-in-a-shell-scrip%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
          1
          down vote













          Here is a one liner:



          sed 's/^.*],/ /' yourfile|tr -d 'n'|sed -e '$a'


          If you are passing this thing as options to a command you may remove the last sed and use



          sed 's/^.*],/ /' yourfile|tr -d 'n'





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:13











          • Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
            – Weijun Zhou
            Dec 7 '17 at 15:03














          up vote
          1
          down vote













          Here is a one liner:



          sed 's/^.*],/ /' yourfile|tr -d 'n'|sed -e '$a'


          If you are passing this thing as options to a command you may remove the last sed and use



          sed 's/^.*],/ /' yourfile|tr -d 'n'





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:13











          • Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
            – Weijun Zhou
            Dec 7 '17 at 15:03












          up vote
          1
          down vote










          up vote
          1
          down vote









          Here is a one liner:



          sed 's/^.*],/ /' yourfile|tr -d 'n'|sed -e '$a'


          If you are passing this thing as options to a command you may remove the last sed and use



          sed 's/^.*],/ /' yourfile|tr -d 'n'





          share|improve this answer












          Here is a one liner:



          sed 's/^.*],/ /' yourfile|tr -d 'n'|sed -e '$a'


          If you are passing this thing as options to a command you may remove the last sed and use



          sed 's/^.*],/ /' yourfile|tr -d 'n'






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 7 '17 at 3:09









          Weijun Zhou

          1,434119




          1,434119











          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:13











          • Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
            – Weijun Zhou
            Dec 7 '17 at 15:03
















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:13











          • Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
            – Weijun Zhou
            Dec 7 '17 at 15:03















          Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
          – André Marques
          Dec 7 '17 at 12:13





          Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
          – André Marques
          Dec 7 '17 at 12:13













          Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
          – Weijun Zhou
          Dec 7 '17 at 15:03




          Sorry to say that but I don't quite understand your question. I suggest that you edit the original post.
          – Weijun Zhou
          Dec 7 '17 at 15:03












          up vote
          1
          down vote













          You could use awk to print the last comma-separated field of each line, and then (provided the argument list does not exceed its limits) xargs to assemble them into a single line:



          $ awk -F, 'print $NF' yourfile | xargs
          106 2556 5207 232 7566 8840 5320





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:17














          up vote
          1
          down vote













          You could use awk to print the last comma-separated field of each line, and then (provided the argument list does not exceed its limits) xargs to assemble them into a single line:



          $ awk -F, 'print $NF' yourfile | xargs
          106 2556 5207 232 7566 8840 5320





          share|improve this answer




















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:17












          up vote
          1
          down vote










          up vote
          1
          down vote









          You could use awk to print the last comma-separated field of each line, and then (provided the argument list does not exceed its limits) xargs to assemble them into a single line:



          $ awk -F, 'print $NF' yourfile | xargs
          106 2556 5207 232 7566 8840 5320





          share|improve this answer












          You could use awk to print the last comma-separated field of each line, and then (provided the argument list does not exceed its limits) xargs to assemble them into a single line:



          $ awk -F, 'print $NF' yourfile | xargs
          106 2556 5207 232 7566 8840 5320






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 7 '17 at 3:51









          steeldriver

          31.8k34979




          31.8k34979











          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:17
















          • Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
            – André Marques
            Dec 7 '17 at 12:17















          Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
          – André Marques
          Dec 7 '17 at 12:17




          Great! It worked nicely... and if I want to designate a variable value for each of the line number? How should I do? Ex. this is my result [1, 2],106 [1, 3],2556 [2, 3],5207 and now I want that: [1, 2],=$area1 ($area1 should be the 106 value) [1, 3],=$area2 (2556) etc
          – André Marques
          Dec 7 '17 at 12:17

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409360%2fneed-to-read-a-file-and-use-results-as-command-line-arguments-in-a-shell-scrip%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?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?