How to add the two columns in different two files.
File1 1 45 2 56 3 56
File2
1 2 2 3 3 4
The Output should come like below 1 47 2 59 3 60
Thanks
How to add the two columns in different two files.
File1 1 45 2 56 3 56
File2
1 2 2 3 3 4
The Output should come like below 1 47 2 59 3 60
Thanks
You could write a simple script in php.
<?php
$f1 = file_get_contents('/path/to/file1');
$f2 = file_get_contents('/path/to/file2');
$cols1 = explode(' ',$f1);
$cols2 = explode(' ',$f2);
for($i=0; $i<sizeof($cols1); $i++) {
echo $cols[$i] + $cols2[$i] . ' ';
}
?>
And if you're going to use this function many times, you could add the ability to use CLI parameters to the script instead of hard coding the file paths.
Try awk
and sed
and by piping them (i.e. |) you can write a onliner to do that for you. Or you can use Perl -e and write a one-liner.