Assalamo Alikum, How are you all?
I use "seq" to generate a sequence of numbers and direct them to a file. Now if I have two files (each with different sequence of numbers) am I able to do simple arithmetics with them? That is, can I add the columns in the first file to the one in the second file? Can I subtract, multipy, and divide the first by the second?
Also, is it possible to do these basic arithmetic operations on just one file? That is, to multiply (divide, add, and subtract) the column of numbers with a constant?
Thanks a lot;
Max
Pretty simple with shell scripting.
man bash
--
Scirpting
Thank you, but now since you mentioned it, How may I learn bash scripting? Do you know a good place to start from? A good book? a good introductory report or assay?
Thank you for ur time,
PS. That was the fastest reply I ever got. M B
the linux documentation
Alaa
"context is over-rated. who are you anyway?"
yes you can do that with
yes you can do that with awk
Alaa
"context is over-rated. who are you anyway?"
bash
Doesn't even need awk, bash can do quite a bit...
--
I meant awk for doing
I meant awk for doing operations on two columns tab3an.
Alaa
"context is over-rated. who are you anyway?"
There're many variant methods
There're many variant methods to do the required operation. Here under are ideas came to me.
If you have 2 files (file1, file2), each of them has one column and u want to multiply each element here with each element there, just use nested for loop like follows:
Of course u can use any operation other than multiplication.
To multiply by constant, just use YoussefAssad code.
But, if each file contain multiple column, use awk (or cut) as follows:
piping to "awk '{print $x}'" extract the column x.
U could also piping to cut -f x -d y which will do the same where x is the column and y is a string (between doublequote) that sets the delimiter.
Otherwise, if file1 and file2 contain one column and u want to multiply each row in file1 to the corresponding column only in file2, use the following code:
Wish this example codes make things more clear to u.
Thanks for these tips mt
Thanks for these tips mt freind, I will try them right away.
Thank you for ur time,
M B