how to divide two columns from two different text files in bash
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.
declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt
shell-script
New contributor
add a comment |Â
up vote
1
down vote
favorite
I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.
declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt
shell-script
New contributor
Are you looking forpaste
?paste File1.txt File2.txt
â unxnut
8 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.
declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt
shell-script
New contributor
I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.
declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt
shell-script
shell-script
New contributor
New contributor
New contributor
asked 14 mins ago
user3708408
61
61
New contributor
New contributor
Are you looking forpaste
?paste File1.txt File2.txt
â unxnut
8 mins ago
add a comment |Â
Are you looking forpaste
?paste File1.txt File2.txt
â unxnut
8 mins ago
Are you looking for
paste
? paste File1.txt File2.txt
â unxnut
8 mins ago
Are you looking for
paste
? paste File1.txt File2.txt
â unxnut
8 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
If what you mean by divide is the mathematical division operation, then try this:
paste inf1 inf2 | awk 'print($1/$2)'
That's assuming that inf1
and inf2
are two files with one column of numbers, something like:
$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364
If you need an specific format then use printf
instead of print
.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If what you mean by divide is the mathematical division operation, then try this:
paste inf1 inf2 | awk 'print($1/$2)'
That's assuming that inf1
and inf2
are two files with one column of numbers, something like:
$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364
If you need an specific format then use printf
instead of print
.
add a comment |Â
up vote
0
down vote
If what you mean by divide is the mathematical division operation, then try this:
paste inf1 inf2 | awk 'print($1/$2)'
That's assuming that inf1
and inf2
are two files with one column of numbers, something like:
$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364
If you need an specific format then use printf
instead of print
.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If what you mean by divide is the mathematical division operation, then try this:
paste inf1 inf2 | awk 'print($1/$2)'
That's assuming that inf1
and inf2
are two files with one column of numbers, something like:
$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364
If you need an specific format then use printf
instead of print
.
If what you mean by divide is the mathematical division operation, then try this:
paste inf1 inf2 | awk 'print($1/$2)'
That's assuming that inf1
and inf2
are two files with one column of numbers, something like:
$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364
If you need an specific format then use printf
instead of print
.
answered 4 secs ago
Isaac
8,72211242
8,72211242
add a comment |Â
add a comment |Â
user3708408 is a new contributor. Be nice, and check out our Code of Conduct.
user3708408 is a new contributor. Be nice, and check out our Code of Conduct.
user3708408 is a new contributor. Be nice, and check out our Code of Conduct.
user3708408 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f478571%2fhow-to-divide-two-columns-from-two-different-text-files-in-bash%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
Are you looking for
paste
?paste File1.txt File2.txt
â unxnut
8 mins ago