Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mixture...

Status
Not open for further replies.

swa75

Technical User
Aug 20, 2002
14
0
0
FR
I need to make a "mixture" of 2 files :

file1 :
123486:120fds
123486:121regd
123486:123gre
123486:124fds
123486:125fds
874135:120fds
874135:121ret
874135:122uyt
874135:123fds
874135:125fds
454631:120fds
454631:121fds
454631:122uyt
454631:123fds
454631:124fds
895230:121fds
895230:122juyr
895230:123fds
895230:124fds
GFDQGRE:121fds
GFDQGRE:122juyr

file2 :
FDQAF-123486 ;gfqdgfd
GREAG-874135 ;gfeytht
GFDQGRE-GFDQGRE ;htrzez
GFDQGRTRE-454631 ;oeroeioz
GFDGTRYT-GFDGTRYT ;rtreatra
GFQ4TR-895230 ;gtrzopo

what I want to obtain :

file 3 :
FDQAF-123486 gfqdgfd 120fds 121regd 123gre 124fds 125fds
GREAG-874135 gfeytht 120fds 121ret 122uyt 123fds 125fds
GFDQGRTRE-454631 oeroeioz 120fds 121fds 122uyt 123fds 124fds
GFQ4TR-895230 gtrzopo 121fds 122juyr 123fds 124fds
GFDQGRE-GFDQGRE htrzez 121fds 122juyr

what I must do is to find the part in red of file2 in the 1st field of file1. If it matches then replace field 1 of file1 by the line of file2. the ";" must be deleted and I need to concatenate all the lines where the field 1 of file1 is the same without repeating the 1st field. The different fields must be ordered in columns. The "120" must be in the same column and if there is no "120" I must put a blank.

I think I need to use awk but it's too hard for my small experience...
I hope it's clear enough. thanks for your help.
 
the columns in file3 must be aligned (I don't know if i can say that...) which doesn't appear in my message...
 
here's something to start you with:

nawk -f mix.awk file2

#--------------------- mix.awk
BEGIN{
OFS=" "
FSfile1=":"

file1="file1"
file2="file2"

FS=FSfile1;
while (getline < file1 > 0) {
# skip comments in the config file
if ( $0 ~ /^[#].*/ ) continue;
if ($1 in arrConf)
arrConf[$1]=arrConf[$1] OFS sprintf(&quot;%-10s&quot;,$2);
else
arrConf[$1]=sprintf(&quot;%-10s&quot;,$2);
}
close(file1);

FS=&quot; &quot;;
}

{
split($1, specARR, &quot;-&quot;);
gsub(&quot;;&quot;,&quot;&quot;, $2);
if (specARR[2] in arrConf)
printf(&quot;%-20s%s%-10s%s%s\n&quot;, $1, OFS, $2, OFS, arrConf[specARR[2]]);
# else
# printf(&quot;%s%s%s\n&quot;, $1, OFS, $2 );
}

END {
}

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top