hi, i'm a beginner in Linux, actually i use andLinux,
i have a data file with 11 columns
170 N SER T 25 56.962 42.701 -133.423 1.00 87.04 N
171 CA SER T 25 57.076 41.790 -132.280 1.00 86.65 C
172 C SER T 25 57.766 40.492 -132.692 1.00 87.52 C
173 O SER T 25 58.653 39.988 -131.992 1.00 86.59 O
174 CB SER T 25 55.694 41.451 -131.730 1.00 85.78 C
175 OG SER T 25 54.981 40.607 -132.622 1.00 77.49 O
i would like write close to 11 th column "12" if in the 11 th column is C or "14" if is N or "16" if is O,
i tried several time only for C but doesn't work
{
atom = $11
if ( atom == " C " )
{
print $11 12
}
else
{
print $11 "no"
}
}
while read LINE
do
Atom=$(echo $LINE | cut -d' ' -f11)
case $Atom in
C ) echo "$Atom 12" ;;
N ) echo "$Atom 14" ;;
O ) echo "$Atom 16" ;;
* ) echo "$Atom no" ;;
esac
done < data
awk '{
if ($NF=="N") {print $11,"14"}
else if ($NF=="C") {print $11,"12"}
else if ($NF=="O") {print $11,"16"}
else {print $11,"no"}
} ' urfile
N 14
C 12
C 12
O 16
C 12
O 16
Thanks so much, but it still no working, if i prepare a file test.awk and i call it by command awk -f test.awk , it writes a column of "no". And if i try to write the command directly on the terminal, it writes nothing and the terminal become useless.
---------- Post updated at 12:59 PM ---------- Previous update was at 10:56 AM ----------
thanks a lot, with your suggestion it works.
thank you.
Elsa:o