Need to read a file and use results as command line arguments in a shell scrip
Clash 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
bash shell
add a comment |Â
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
bash shell
add a comment |Â
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
bash shell
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
bash shell
edited Dec 8 '17 at 5:58
asked Dec 7 '17 at 2:43
André Marques
62
62
add a comment |Â
add a comment |Â
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'
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
add a comment |Â
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
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
add a comment |Â
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'
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
add a comment |Â
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'
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
add a comment |Â
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'
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'
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password