954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Math Process on data form different data files

Hi everyone,

Here is my problem:

I have different data files each with several columns and row of data.
datafile1 , datafile2, ...

Now I need to do some simple math procedure of this data files, Lets say I need to add the 3rd column of datafile1 to the 2nd column of the datafile2.

I was thinking to write a shell script that does so, but I don't have a clue where to start. Any suggestion is very appreciated.

SakuraPink
Light Poster
31 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This might be along the lines of what you were looking for.

#! /bin/bash

while : do
  read a <&4 || break
  read b <&5 || break
  set a
  col3=$3
  set b
  col2=$2
  echo $(($col3+$col2))
done 4<datafile1 5<datafile2


However, bash can be awkward handling multiple files. Perl or gawk would be better.

Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You