awk script required

File 1

###################

TRAIU DSKDL; SLLA ;LAKJA

KJAJA NSAJAN JANAL AJKJA

JAJALA KAKAK JA AKA AKA AJ A A

PPIN TRY1 SANT1 PPIN TRY2 SANT2

PPIN TRY3 SANT3 PPIN TRY4 SANT4

PPIN TRY5 SANT5

AJJA NA ANA ANHDJLD ALJALJA

AJLJAJD LALJAL ALJALJA ALJALJA

JAKHAL AKJALA LAJL;AJ

File 2

#####################

PAD1 TRY1

PAD2 TRY2

PAD3 TRY3

PAD4 TRY4

PAD5 TRY5

######################

OUTPUT FILE 1

##############################

TRAIU DSKDL; SLLA ;LAKJA

KJAJA NSAJAN JANAL AJKJA

JAJALA KAKAK JA AKA AKA AJ A A

PPIN TRY1 SANT1 PAD1

PPIN TRY2 SANT2 PAD2

PPIN TRY3 SANT3 PAD3

PPIN TRY4 SANT4 PAD4

PPIN TRY5 SANT5 PAD5

AJJA NA ANA ANHDJLD ALJALJA

AJLJAJD LALJAL ALJALJA ALJALJA

JAKHAL AKJALA LAJL;AJ

I am new to awk , Can you guys help me out for an awk script FILE 1 is having some keywords which need to be matched up with FILE 2 Keywords TRY 1 TRY2 TRY3 (Pattern which need to be searched in FILE 1 will be PPIN and the keywords of the FILE 2 like TRY1 TRY2 etc ) and then output should be generated in FILE1 where other keywords in the FILE2 will be appended as shown in the OUTPUT FILE

Thanks Jaita

Nobody can read this. Use code tags to represent code, data or logs. You got a PM how to do that. Also what have you tried on your own so far?

Hi

I have tried it on my own but could not able to make a generic script , Tried to extract the keywords and used VI editor skills to reach to the output but I need a generic awk script

Thanks
Jaita

---------- Post updated at 06:24 AM ---------- Previous update was at 06:23 AM ----------

File 1

###################

TRAIU DSKDL; SLLA ;LAKJA

KJAJA NSAJAN JANAL AJKJA

JAJALA KAKAK JA AKA AKA AJ A A

PPIN TRY1 SANT1

PPIN TRY2 SANT2

PPIN TRY3 SANT3

PPIN TRY4 SANT4

PPIN TRY5 SANT5

AJJA NA ANA ANHDJLD ALJALJA

AJLJAJD LALJAL ALJALJA ALJALJA

JAKHAL AKJALA LAJL;AJ

File 2

#####################

PAD1 TRY1

PAD2 TRY2

PAD3 TRY3

PAD4 TRY4

PAD5 TRY5

######################

oUTPUT

FILE 1

##############################

TRAIU DSKDL; SLLA ;LAKJA

KJAJA NSAJAN JANAL AJKJA

JAJALA KAKAK JA AKA AKA AJ A A

PPIN TRY1 SANT1 PAD1

PPIN TRY2 SANT2 PAD2

PIN TRY3 SANT3 PAD3

PPIN TRY4 SANT4 PAD4

PPIN TRY5 SANT5 PAD5

AJJA NA ANA ANHDJLD ALJALJA

AJLJAJD LALJAL ALJALJA ALJALJA

JAKHAL AKJALA LAJL;AJ

---------- Post updated at 06:25 AM ---------- Previous update was at 06:24 AM ----------

I am new to awk , Can you guys help me out for an awk script
FILE 1 is having some keywords which need to be matched up with FILE 2 Keywords TRY 1 TRY2 TRY3 and then output should be generated in FILE1 where other keywrods in the FILE2 will be appended as shown in the OUTPUT FILE

Thanks
Jaita

---------- Post updated at 06:28 AM ---------- Previous update was at 06:25 AM ----------

Matching pattern in the FILE1 is Keywords in FILE2 TRY1 TRY2 etc and PPIN of FILE1

I tried to extract the PPIN Block in some other file

awk '/PPIN/ {print $0}' FILE1 and then used some VI editor thing to reach to the output

But if I get a generic script then it would be great

Something like:

# awk 'NR==FNR{a[$2]=$1;next}{if(/PPIN/){for(i=0;++i<=NF;){printf (i%3)?$i FS:$i FS a[$(i-1)] RS ((i==NF)?x:RS)}}else{print}}' file2 file1
TRAIU DSKDL; SLLA ;LAKJA

KJAJA NSAJAN JANAL AJKJA

JAJALA KAKAK JA AKA AKA AJ A A

PPIN TRY1 SANT1 PAD1

PPIN TRY2 SANT2 PAD2

PPIN TRY3 SANT3 PAD3

PPIN TRY4 SANT4 PAD4

PPIN TRY5 SANT5 PAD5

AJJA NA ANA ANHDJLD  ALJALJA

AJLJAJD LALJAL ALJALJA ALJALJA

JAKHAL AKJALA LAJL;AJ

Hi

Thanks for the Reply
Can you make me understand this code as well ...
I would be easy for me to take it forward for some future issues as well

Thanks
Jaita