help needed using awk scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help needed using awk scripting
# 1  
Old 08-12-2010
help needed using awk scripting

Hi,
I've few files in the following format

file 1
-------------------------
Code:
A=a1      B=0    C=1    D=3
A=a2      B=0    C=1    D=3
A=a3      B=0    C=6    D=7
A=a4      B=0    C=1    D=3
A=a5      B=0    C=1    D=3

file 2
-------------------------
Code:
A=a1      B=2    C=2    D=4
A=a2      B=6    C=2    D=8
A=a3      B=4    C=3    D=4
A=a4      B=0    C=4    D=6
A=a5      B=0    C=2    D=4


file 3
-------------------------
Code:
A=a1      B=0    C=3    D=1
A=a2      B=1    C=2    D=2
A=a3      B=0    C=1    D=3
A=a4      B=4    C=5    D=4
A=a5      B=0    C=6    D=5

Now, I want a resulting file which will be adding up all these values in the following format.

file new
-------------------------------
Code:
A=a1      B=2    C=6    D=8
A=a2      B=7    C=5    D=13
A=a3      B=4    C=10   D=14
A=a4      B=4    C=10   D=13
A=a5      B=0    C=9    D=12

could you please help me with this using awk or sed scripting...


Thanks in advance

Last edited by Franklin52; 08-12-2010 at 01:09 PM.. Reason: Please use code tags
# 2  
Old 08-12-2010
Sure awk gurus will find something but here's a shell way to do it (works by me)
Code:
#!/bin/bash
join file1 file2 > file4
join file4 file3 | while read A B1 C1 D1 B2 C2 D2 B3 C3 D3 
do	echo -e "$A\tB=$((B1+B2+B3))\tC=$((C1+C2+C3))\tD=$((D1+D2+D3))"
done

# 3  
Old 08-13-2010
Hi

Assuming your files are a1, a2 and a3:

Code:
#join a1 a2 | join - a3 | awk '{for(i=3;i<=NF;i+=2)a[$i]+=$(i+1)}{printf "%s=%s\t",$1,$2;for (i in a)printf "%s=%d\t", i,a[i],a[i]=0;print "";}' FS="[ =]"
A=a1    B=2     C=6     D=8
A=a2    B=7     C=5     D=13
A=a3    B=4     C=10    D=14
A=a4    B=4     C=10    D=13
A=a5    B=0     C=9     D=12
#

Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting Help needed

Hi folks, need a small help lets say i have a text file with the following content: james tom jack spielberg i want to append text to the beginning of each line with a variable(lets says FirName:) and i want to combine all the names with a space in between and store it in another... (11 Replies)
Discussion started by: tech_frk
11 Replies

2. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

3. Shell Programming and Scripting

Help needed in scripting

Hi Guys, I need help in scripting out the below : this is a sample data i have in my file: jobname type 8:00:00 AM I need to remove the ":00" from the time field alone. Thanks in advance for all ur help (8 Replies)
Discussion started by: a12ka4
8 Replies

4. Shell Programming and Scripting

Scripting help needed

Hi All, I have a conf file and it has two entries seperated by comma, look like :- best1,ls /opt/bmc/Patrol3/*/best1 ......, ....................... In which "Best1" is the product name and "ls /opt/bmc/Patrol3/*/best1" is the way to find the product version of Best1 in that particular... (5 Replies)
Discussion started by: Renjesh
5 Replies

5. Homework & Coursework Questions

Scripting needed

Hi, My task is to check the file test.txt every 15 min from Mon-Fri 9:00AM - 6:00PM. We get this file from our mainframes, every 15 min it will update the same file. My task is to compare file timestamp with current system time stamp and check if the file is updated or not. If the file doesn't... (0 Replies)
Discussion started by: chinniforu2003
0 Replies

6. Shell Programming and Scripting

Help needed with scripting.

Hello Friends, I am very new to scripting and currently have come across a situation where I need to create a UNIX script which would look for certain text in a file and then email me if it finds it. I am trying to trouble shoot an issue with our internet websites and I need to know when I... (1 Reply)
Discussion started by: mahive
1 Replies

7. Shell Programming and Scripting

sed or awk scripting help needed

hi all, for an example : df -k output shows: $ df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p6 3099260 1117760 1824068 8% / /dev/cciss/c0d0p1 256666 18065 225349 8% /boot none 8219180 0 8219180 0% /dev/shm /dev/mapper/vglocal-home 1032088 245172 734488 26%... (7 Replies)
Discussion started by: raghur77
7 Replies

8. UNIX for Dummies Questions & Answers

sh scripting! Help Needed

Hello fellas or ladies. I am new on this site and new to the unix operating system. I have been working with UNIX and i love it so far, i learned some stuff and most of the beneficiary command but I need help renaming all the files in my directory and doing them one by one is just tiring. is there... (3 Replies)
Discussion started by: keyboardkowboy
3 Replies

9. Shell Programming and Scripting

sh scripting! Help Needed

Hello fellas or ladies. I am new on this site and new to the unix operating system. I have been working with UNIX and i love it so far, i learned some stuff and most of the beneficiary command but I need help renaming all the files in my directory and doing them one by one is just tiring.... (1 Reply)
Discussion started by: keyboardkowboy
1 Replies

10. Shell Programming and Scripting

little scripting help needed!!

guys i need bit of help!! i am writing a script which finds files that have not been accessed for a no of days and delete those files...the no of days value is inputted at the command line.... i am using the following : find $1 -atime +7 -exec rm -i in the second step i want to copy all... (2 Replies)
Discussion started by: vats
2 Replies
Login or Register to Ask a Question