File Alter Problem--need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Alter Problem--need help
# 1  
Old 06-20-2008
File Merging Problem

i have 3 files
a.txt , b.txt and c.txt
each files have keyfields and some column fields
e.g.
a.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3
1 2 3 44 55 66
4 5 6 92 48 33
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4
1 2 3 44 55 66 78
4 5 6 92 48 33 99
.....................etc..................
b.txt
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
7 8 9 447 255 366 678 25
4 5 6 92 48 33 97 43
1 2 3 44 55 66 78 88
.....................etc..................
key fields are the primary keys to these above files
here 1 st key is 123then
script will check a.txt's col1,col2,col3 to b.txt's col1,col2,col3 and c.txt's col1,col2,col3
for the key field 123
here all values are equal for key field 123 if not matches then script will exit for further checking telling that for key field 123 initial matches are not OK .

so it will append result.txt
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66
then since b.txt and c.txt have some extra columns col4 and col5
so it will check col4 of b.txt with col4 of c.txt
if it matches then matching value will be there if not matching then nonmatch vales separted by comma will be there
so result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78
here col5 is the extra column in c.txt for the same keyfield 123, so simply this will be placed as col5
so result.txt will be
as
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
similary for keyfiled 456 result.xtx will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
if any file has extra line(s) and has no matches to any files then it will simply append into the result.txt
so final result.txt will be
keyfield1 keyfield2 keyfield3 col1 col2 col3 col4 col5
1 2 3 44 55 66 78 88
4 5 6 92 48 33 99,97 43
7 8 9 447 255 366 678 25

i am not sure, whether i expalined my situtaion prperly or not. but please let me know if it's not.
but if so, then kindly let me know how to achieve this ????

NOTE: Ther might be n number of columns..depends on the requirement . So script should accumulate such number of columns dynamaically .

Last edited by manas_ranjan; 06-20-2008 at 11:53 AM..
# 2  
Old 06-23-2008
Any help in this regard ????
# 3  
Old 06-23-2008
Do not post problems without trying to solve the problem yourself based on your understanding. Anyway , look like a homework.
Post what have you tried so far and where exactly are you stuck.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alter existing script to work with longer file name

I have this script: #!/bin/sh for file in "$@" do ext=${file##*.} base=${file%.*} num=${base##*v} zeroes=${num%%*} num=${num#$zeroes} #remove leading zeros, or it uses octal num=$((num+1)) base=${base%v*} new=$(printf... (4 Replies)
Discussion started by: scribling
4 Replies

2. Shell Programming and Scripting

Alter Fixed Width File

Thank u so much .Its working fine as expected. ---------- Post updated at 03:41 PM ---------- Previous update was at 01:46 PM ---------- I need one more help. I have another file(fixed length) that will get negative value (ex:-00000000003000) in postion (98 - 112) then i have to... (6 Replies)
Discussion started by: vinus
6 Replies

3. Shell Programming and Scripting

How to get MD5 from a pipe stream and do not alter it?

Say I have a stream and want to get MD5 from it, without altering it. I won't know how big the stream is or how much time it will take to close. Here is the idea: cat somefile | calculate md5 and put it somewhere | bzip2 > somefile.bz2 (5 Replies)
Discussion started by: Tribe
5 Replies

4. UNIX for Dummies Questions & Answers

alter data in a file

Hi , I have data in file like below. status ----------- ------ 2287 C 1502 E 19 can anyone pls help me how can i get it modified as below status 2287|C|1502 E|19 can someone pls help. Thanks. (2 Replies)
Discussion started by: gaddamja
2 Replies

5. Homework & Coursework Questions

Help with bash shell to alter text file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: My first question pertains to the adding a book section, I'm unsure which command or conditional statement I... (0 Replies)
Discussion started by: Vitrophyre
0 Replies

6. Shell Programming and Scripting

Alter file descriptor for stdout

Is there a way to alter the file descriptor for stdout.? sample: #!/bin/ksh exec 1>file exec 2>file echo hi --------->This will go to file print -u4 "come statement"---->I want to make the file descriptor 4 to point to stdout. The reason is ,I have a script which has lot of db2... (1 Reply)
Discussion started by: prasperl
1 Replies

7. UNIX for Dummies Questions & Answers

alter data in column

Hello All, I want to alter the first column of a dataset, say, 001 0.700 100.000 002 0.715 99.998 003 0.730 99.998 004 0.744 99.975 005 0.759 99.916 011 0.847 97.987 012 0.861 97.317 020 0.978 87.789 021 0.993 86.400 022 1.008 84.904 023 1.022 83.014 100 2.148 11.426 101... (2 Replies)
Discussion started by: tintin72
2 Replies

8. Solaris

Alter zip file without unzipping

I have some zip files. Every file has a "folder/xml file" inside it. Is there any way to change these zip files directly without unzipping them. I want to convert these zip files to "/xml file" (want to move the xml file/s one root up by removing the folder inside it.) Ex: -bash-3.00$ for file... (1 Reply)
Discussion started by: _prasad
1 Replies

9. AIX

Can't alter bootlist

Made a sysback tape backup on our 595 running 4.1.5 but when trying to do a restore discovered that rmt0 not in bootlist(s). Tried to alter both the normal and service bootlists but system wont respond to F7(commit). Erased the service boolist then tried alter again, same result. Now have... (2 Replies)
Discussion started by: mooshkie
2 Replies

10. UNIX for Dummies Questions & Answers

how to alter the old file permanently using sed?

hi , m new to sed and awk. can anyone tell me how to alter the old file permanenetly using sed. e.g. $sed 's/cat/dog/g' old_file the above command will replace all the occrance of cat by dog in the file called old_file and by default will show the output at stdout. so is there anyway of... (2 Replies)
Discussion started by: mxms755
2 Replies
Login or Register to Ask a Question