reading from two files and manipulating the data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading from two files and manipulating the data
# 1  
Old 04-14-2011
reading from two files and manipulating the data

hi
i have a file of the following format
Code:
FILE1
 5      937      8
 1860   1850     1
 683    2        1
 129    2        2
 5      938      8
 1122   1123     1
 20     520      4
 1860   1851     1
 5      939      8
 1122   1124     1
 20     521      4

i have another file which holds a single number (which is nothing but the sum of all values stored in third column above) I did it with
Code:
 awk '{ sum+=$3}; END { print sum} > file2 '

i want to divide each number stored in third column of first file by a number stored in the second file and output it to the file

how can i deal with this issue ?Smilie

thanks in advance Smilie
# 2  
Old 04-14-2011
please provide input and output examples
# 3  
Old 04-14-2011
lets say for above example the sum of third column will be 39
now the file two will consist this sum = 39 only

so the desired processing should be like

Code:
8/39 = 0.205128205 
1/39 = 0.025641026 
1/39 = 0.025641026 
2/39 = 0.051282051 
8/39 = 0.205128205 
1/39 = 0.025641026 
4/39 = 0.102564103 
1/39 = 0.025641026 
8/39 = 0.205128205 
1/39 = 0.025641026 
4/39 = 0.102564103

all the values coming as the output in above calculations should be stored along with first 3 columns in file1
# 4  
Old 04-14-2011
With one awk command:
Code:
awk 'NR==FNR{sum+=$3;next}{print $3 "/" sum " = " $3/sum}' OFS="\t" FILE1 FILE1

This User Gave Thanks to Franklin52 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies

2. Shell Programming and Scripting

Data manipulating script. Please HELP!

Dear friends, I'm struggling to preparing a bunch of gromacs input files, say manually. It's really a time-consuming work without any techniques. I suppose that it could be done by a smart script automatically. But I lack some basic knowledge on scripting. Please help! My original input looks... (3 Replies)
Discussion started by: liuzhencc
3 Replies

3. Programming

Reading data from files

I have a list of files, 4 files for example Then I have two buffers ifa and ifb giving me the file numbers from which I need to get a group of data. For example, the first four groups use file 1. The fifth group uses data from file 1 and file 2. I am thinking of storing all the data in the... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

Reading 2 CSV files and filtering data based on group

I have two CSV files in the following format: First file: GroupID, PID:TID, IP, Port Sample data: 0,1000:11,127.0.0.1,445 0,-1:-1,127.0.0.1,800 1,1000:11,127.0.0.1,445 1,-1:-1,127.0.0.1,900 2,1000:11,127.0.0.1,445 2,-1:-1,180.0.0.3,900 Second file: IP,Port,PID Sample data... (6 Replies)
Discussion started by: rakesh_arxmind
6 Replies

5. UNIX for Dummies Questions & Answers

Reading and writing data to and from multiple files

Hi, I have several text files. One main file contains the detail data, other have some information to extract data from the main file, and some are empty files. Examples are shown below: The main file look like: MainFile.txt >Header1 data1...data1... >Header2 data2...data2... ... ...... (2 Replies)
Discussion started by: Fahmida
2 Replies

6. Shell Programming and Scripting

manipulating data

Hi guys Firstly, I'd like to say hi and how great this forum is. I'm not new to UNIX but am relatively new to scripting. I have a personal project that I'm working on just to try and speed up my learning. I working with a text file, well more of a logfile really. It has several columns of... (6 Replies)
Discussion started by: abcd69
6 Replies

7. Emergency UNIX and Linux Support

Manipulating Data

Hi. I haven't had to write bash scripts in a long time and have a simple task to do, but need some help: Input: chrY:22627291-22651542 chrY:23045932-23070172 chrY:23684890-23696359 chrY:25318610-25330083 chrY:25451096-25462570 chr10:1054847-1061799 chr10:1058606-1080131... (7 Replies)
Discussion started by: awknerd
7 Replies

8. UNIX for Dummies Questions & Answers

reading ,writing,appending ,manipulating a file.

Hi my prob statement is to create a new file or to append to the 1tst file the followign chages. File 1: txt file. portfolio No a b c d abc 1 Any Any Any charString cds 2 values values values charString efd 3 can can can charString fdg 4 come come come charString... (4 Replies)
Discussion started by: szchmaltz
4 Replies

9. Shell Programming and Scripting

Manipulating data in variable

Hi, I have two variables - A and B - containing a bunch of file paths. I am comparing them and when I find a match I want to remove that entry from A so that as the compare proceeds A shrinks entry by entry. How can I remove a matched entry from A whilst leaving the non matched entries... (6 Replies)
Discussion started by: ajcannon
6 Replies

10. Cybersecurity

Reading and Manipulating captured packets (pflog file)

Hey, I currently have a set of captured sessions thru ethereal, saved in pflog files, basically its a tcpdump, which i need to go thru and sort the applications/protocols in order of the times they were used. I also need to change the headers of the packets, basically the source and destination... (0 Replies)
Discussion started by: PenguinDevil
0 Replies
Login or Register to Ask a Question