pls help

Hi,
I need your help guys. I have two data files, namely 101.amberized.pdb & 101.pdb .

Now I want to replace the whole 3rd column of 101.amberized.pdb with the 3rd column of 101.pdb file. How do I do it in shell?
Thanks in advance

Parimal

You can use join command if you have common fields. Else show your input files?

Dear Parimal,
if you want to replace only 3rd column then,
first use sed command like,

#!/bin/sh
var1=`sed -n '3p' 101.pdb `
var2=`sed -n '3p' 101.amberized.pdb`

sed -n 's/$var2/$var1/' 101.amberized.pdb >> outfile.txt

gud luk...

Panknil,
The '3p' option in the "sed" command will print the third line/record
in the file, not the third column in each record.
As Anbu said, we need a sample of both files to find a solution.

Dear Shelllife,
initially i made mistake to understand the requirement,

if he wants to replace the 3rd column then he can use,

#!/bin/sh
var1=`awk -F 'FS' '{print $3}' 101.pdb`
var2=`awk -F 'FS' '{print $3}' 101.amberized.pdb`
sed -n 's/$var2/$var1/g' 101.amberized.pdb >> outfile.txt

*FS= Field Seperator
it will work...
Gud luk

I think you can do as follow:
Suppose the content of fir is
a b c
d e f
the content of sec is
A B C
D E F

THEN,
i=1
while read line
do
t=`awk '{if(NR=="'"$i"'") print $2}' sec`
tt=`echo $line | awk '{print $2}'`
echo $line | sed "s/$tt/$t"
let i=i+1
done < fir

Then the output will be
a B c
d E f

Hope this will be what you desired
:smiley:

Dear friend panknil,
you'll need to re-read both the original post and the 'man awk'. You'll also need to brush up on the differences between the double-quotes and the single-quotes in shells.
101.pdb:

a b c
d e f

101.amberized.pdb

A B C
D E F

nawk -f chuchu.awk 101.pdb 101.amberized.pdb

chuchu.awk:

FNR==NR { arr[FNR]=$3; next}
{ $3=arr[FNR];print}

dear vgersh99,
you are right i need to read the man awk cause there are so many things to learn still...
but i dont think that whatever i have sent its wrong...
cause its fully tested my dear friend...
and it was working fine...

so better you also read carefully the requirement and also the reply..ok?

Thnkx,
Pankaj

running the script on Solaris - returned no data. I must be missing something very obvious. could you post what you're seeing, pls?

Fully tested ? Are you sure ?

$ cat 101.pdb 
a b c
d e f
$ cat 101.amberized.pdb 
A B C
D E F
$ rm -f outfile.txt
$ cat chuchu.sh
#!/bin/sh
var1=`awk -F ' ' '{print $3}' 101.pdb`
var2=`awk -F ' ' '{print $3}' 101.amberized.pdb`
sed -n 's/$var2/$var1/g' 101.amberized.pdb >> outfile.txt
$ sh -x chuchu.sh
+ + awk -F   {print $3} 101.pdb
var1=
+ + awk -F   {print $3} 101.amberized.pdb
var2=
+ sed -n s/$var2/$var1/g 101.amberized.pdb
+ 1>> outfile.txt
$ cat outfile.txt
$ 

Panknil,
Your solution does not work.
It will set 'var1' with all the third column in '101.pdb' and
'var2' will all the third column in '101.amberized.pdb'.
Then you tried to execute 'sed' to replace all the third columns
from one file to another file at once -- it does not work, as stated
above by Vgersh and Aigles.

Guys,
The two files look like this:

101.pdb looks like:

                     AM1 CALCULATION

                                            LocalSCF2         1.0
                                            Thu Nov 30 19:55:15 2006

      EMPIRICAL FORMULA: C972 H1443 N254 O285 S9

AM1 1SCF CHARGE=-5 PDBINP GEO-OK USEFMM

 SCF FIELD WAS ACHIEVED


      HEAT OF FORMATION       =      -5441.095651 KCAL =     -22765.54420 KJ
      TOTAL ENERGY            =    -279587.680092 EV
      ELECTRONIC ENERGY       =   -9120618.893231 EV
      CORE-CORE REPULSION     =    8841031.213139 EV
      atheat                  =    6677719.524081 kcal
      DIPOLE                  =        427.38051 DEBYE    SYMMETRY:       C1
      NO. OF FILLED LEVELS    =       4185
      MOLECULAR WEIGHT        =     21535.163
      SCF CALCULATIONS        =         1
      COMPUTATION TIME =         381.69 SECONDS




                       Net atomic charges

Atom No. Type Charge No. of elecs. s-Pop p-Pop
1 N -0.050845 5.0508 1.43492 3.61592
2 H 0.270236 0.7298 0.72976
3 H 0.252319 0.7477 0.74768
4 H 0.234913 0.7651 0.76509
5 C -0.113602 4.1136 1.25325 2.86035
6 H 0.191044 0.8090 0.80896
7 C -0.168786 4.1688 1.19808 2.97071
8 H 0.091344 0.9087 0.90866
9 H 0.188577 0.8114 0.81142
10 C -0.144850 4.1449 1.18795 2.95690
11 C -0.149641 4.1496 1.20348 2.94616
12 H 0.102619 0.8974 0.89738
13 C -0.124950 4.1249 1.22177 2.90318
14 H 0.132802 0.8672 0.86720
15 C -0.092942 4.0929 1.23475 2.85819
16 H 0.164127 0.8359 0.83587
17 C -0.109979 4.1100 1.23665 2.87333
18 H 0.173796 0.8262 0.82620
19 C -0.092526 4.0925 1.23531 2.85721
20 H 0.181277 0.8187 0.81872

I have to grep the 3rd column & replace the 9th column of 101.amberized.pdb file which looks like:

ATOM 1 N PHE 1 -5.811 0.058 -26.716 0.173700 2.006 0.170 N3
ATOM 2 H1 PHE 1 -5.560 -0.954 -26.786 0.192100 0.642 0.016 H
ATOM 3 H2 PHE 1 -5.253 0.504 -27.408 0.192100 0.642 0.016 H
ATOM 4 H3 PHE 1 -6.797 0.179 -26.813 0.192100 0.642 0.016 H
ATOM 5 CA PHE 1 -5.253 0.487 -25.446 0.085900 2.042 0.109 CT
ATOM 6 HA PHE 1 -5.500 -0.259 -24.676 0.104100 1.484 0.016 H1
ATOM 7 CB PHE 1 -3.780 0.463 -25.635 -0.034300 2.042 0.109 CT
ATOM 8 HB2 PHE 1 -3.532 0.703 -26.669 0.029500 1.591 0.016 HC
ATOM 9 HB3 PHE 1 -3.387 1.233 -24.984 0.029500 1.591 0.016 HC
ATOM 10 CG PHE 1 -3.037 -0.743 -25.227 0.011800 2.042 0.086 CA
ATOM 11 CD1 PHE 1 -2.446 -1.525 -26.185 -0.125600 2.042 0.086 CA
ATOM 12 HD1 PHE 1 -2.611 -1.374 -27.225 0.133000 1.561 0.015 HA
ATOM 13 CE1 PHE 1 -1.687 -2.631 -25.813 -0.170400 2.042 0.086 CA
ATOM 14 HE1 PHE 1 -1.239 -3.154 -26.651 0.143000 1.561 0.015 HA
ATOM 15 CZ PHE 1 -1.383 -2.883 -24.442 -0.107200 2.042 0.086 CA
ATOM 16 HZ PHE 1 -0.667 -3.612 -24.038 0.129700 1.561 0.015 HA
ATOM 17 CE2 PHE 1 -2.041 -2.104 -23.470 -0.170400 2.042 0.086 CA
ATOM 18 HE2 PHE 1 -1.853 -2.350 -22.418 0.143000 1.561 0.015 HA
ATOM 19 CD2 PHE 1 -2.958 -1.089 -23.853 -0.125600 2.042 0.086 CA
ATOM 20 HD2 PHE 1 -3.486 -0.538 -23.067 0.133000 1.561 0.015 HA

Thanks for yours help. Hope now you guys can give me a concrete solution of my problem..