Modifying the final output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifying the final output file
# 1  
Old 10-10-2006
Modifying the final output file

Hey all,

I am haivng n number of files all of them are of the same format but different details. i.e

File1 is having the folloeing details:
"Account1",123
"Account2",10
"Account3",12355
"Accountn",555

File2 is having the folloeing details:
"Account1",1234
"Account2",100
"Account3",2290
"Accountn",679

and so on.....so as you can see i am having n number of files, all files have the same account number inside and the only difference is in the number of recrods each account has in each file.....Now what i want to do is to generate a final file which will have all the accounts mentioned earlier along with their records, it will be somehow i a table format.i.e.:

Final output file should look like the following:
"Account1",123,1234
"Account2",10,100
"Account3",12355,2290
"Accountn",555,679

Any idea on how to do this?
# 2  
Old 10-10-2006
try something like this

Code:
awk -F"," ' 
{ arr[$1]=arr[$1] FS $2 }
END{
for key in arr
{
print key "," arr[key]
}
}' *

# 3  
Old 10-10-2006
anbu23,
have you tried you solution?

nawk -f char.awk file2.txt file1.txt

char.awk:
Code:
BEGIN {
  FS=OFS=","
}
FNR==NR { arr[ $1 ] = $2; next }
{ print $0, arr[ $1 ] }


Last edited by vgersh99; 10-10-2006 at 01:24 PM..
# 4  
Old 10-10-2006
Code:
join -t"," file1 file2

# 5  
Old 10-10-2006
A variation of anbu23's script, which is what I think he was attempting (less syntax errors Smilie )
Code:
nawk -F"," '
    BEGIN { FS=OFS="," }

    { arr[ $1 ] = (arr[ $1 ]) ? arr[ $1 ] FS $2 : $2 }

END { for (i in arr) print i, arr[i] }
' file_1 file_2 file_n

This solution allows for any number of files beyond file 2.
# 6  
Old 10-10-2006
Quote:
Originally Posted by vgersh99
anbu23,
have you tried you solution?

nawk -f char.awk file2.txt file1.txt

char.awk:
Code:
BEGIN {
  FS=OFS=","
}
FNR==NR { arr[ $1 ] = $2; next }
{ print $0, arr[ $1 ] }

I didn't test my code.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Separating output after final character

I'm trying to write a script that will email the contents of my Application folder to me. cd /Applications ListApps=$(ls) echo $ListApps | mail -s "Application Check" myself@myemail.com This sends it in a paragraphed block i.e: Adobe Acrobat Reader.app App Store.app Atom.app... (4 Replies)
Discussion started by: $shell_Learner
4 Replies

2. Shell Programming and Scripting

Modifying output column

Hi friends, I have file as follow D1 pin16I pin20I R1 pin20F pin20D VCC1 pin20A pin16G I want to modify it second and third column. I want to just change the last character of 2nd and 3rd column with some condition. The condition is if last char of second column is in... (7 Replies)
Discussion started by: diehard
7 Replies

3. Shell Programming and Scripting

Addition to Bash shell script that emails final output as attachement?

Greetings. I have a nice bash shell script that runs a multi-step analysis well. I already have the SGE options set up to email me the progress of the run (started, completed, aborted), but a final step would be to code the shell script to email the final output (a .txt file) to the same email... (6 Replies)
Discussion started by: Twinklefingers
6 Replies

4. UNIX for Dummies Questions & Answers

LINUX - How to remove the final delimiter from a command output

Hi All, I am trying to list the various dates for which the file is available in a directory using the command below, (& subsequently pass the command output to a loop) Command : ls dir|grep 'filename'|cut -d '_' -f1|cut -c1-8|tr '\n' ',' However, it is giving me an extra comma... (6 Replies)
Discussion started by: dsfreddie
6 Replies

5. Shell Programming and Scripting

can someone help me with modifying this file

Hi, I have a file which has data kind of like this. Apr 13 08:20:38 uslis10a sendmail: m3DDKSx3006432: usliss26.ca.com Apr 13 08:20:38 uslis10b sendmail: m3DDKSoK006433: usliss26.ca.com Apr 13 08:20:38 uslis10b sendmail: m3DDKcSo006442: usliss26.ca.com Apr 13 08:20:38 uslis10c... (2 Replies)
Discussion started by: eamani_sun
2 Replies

6. Shell Programming and Scripting

Final Output

Hi There, I am having two output files having the following information: Output1: Name1 0 Name2 222 Name3 598 Name4 9800 Output2: Name1 10 Name2 333 Name3 567 Name4 39003 as you can see the two output files have the same Name colom but different records for each name. Now, how... (4 Replies)
Discussion started by: charbel
4 Replies
Login or Register to Ask a Question