Saving output from awk into a perl variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Saving output from awk into a perl variable
# 8  
Old 10-09-2008
why not split?
a2156z
# 9  
Old 10-09-2008
Code:
for (@test)
{
   $last = `awk '/OXT/{print \$4}' $_`;
   $lastnum = `awk '/OXT/{print \$5}' $_`;
   system("sed -i -e '/O    ${last}    ${lastnum}/{s/-0.51000\$/-0.25500/;}' $_");
   system("sed -i -e '/OXT  ${last}    ${lastnum}/{s/-0.67000\$/-0.25500/;}' $_");
}

Thanks guys for your help. The variables are saving the awk output correctly, but when I try to use it in the following sed commands to replace the values shown, it fails.

This is what I want in the end: Find the line that contains OXT and grab the 4th and 5th values and save them to the variables indicated. Then I want to locate the lines that contain OXT followed by the 4th column value (GLY in this case) and by the 5th column value (319 in this case) and replace the number in the last column with the value shown in my sed line. Then I need to make the same replacement with the line that contains O followed by the 4th column value (GLY) and then by the 5th column value (319).

Below is a segment of a single file that I need to make the 2 replacement in. The bolded values are the numbers I need to replace with the values shown in the sed line. The thing is, the line that contains the O might not be next to the OXT line. It could be a random numbers of lines above. Each file in my set is the amino acid sequence and connectivity of different proteins. So the format of each file is uniform, but the actual data is different. Each file will have a single line that contains OXT, which is always located in the last amino acid residue. So I get the residue abberviation and number of the last amino acid by storing the 4th and 5th column value. Then I need to locate the O (oxygen) that is also located in the last residue (GLY 319) in the example file below and make the replacement of the last column value for this line and the line that contains OXT.

Pardon my poor programming mannerisms and improper perl usage, but I can better understand what is going on when I use awk and sed in my Perl script.


Code:
   ATOM    4539 HCB   LEU    318   -7.05103  -5.58173  17.60062 H_     1 0  0.09000
   ATOM    4540 HCB   LEU    318   -7.27904  -5.68284  15.87021 H_     1 0  0.09000
   ATOM    4541  CG   LEU    318   -7.65157  -7.53041  16.94206 C_3    4 0 -0.09000
   ATOM    4542 HCG   LEU    318   -6.58580  -7.79332  16.96207 H_     1 0  0.09000
   ATOM    4543  CD1  LEU    318   -8.26957  -8.08733  18.25040 C_3    4 0 -0.27000
   ATOM    4544 HCD1  LEU    318   -9.36063  -8.06637  18.20792 H_     1 0  0.09000
   ATOM    4545 HCD1  LEU    318   -7.95865  -9.12417  18.39911 H_     1 0  0.09000
   ATOM    4546 HCD1  LEU    318   -7.94214  -7.50413  19.11073 H_     1 0  0.09000
   ATOM    4547  CD2  LEU    318   -8.24821  -8.25377  15.71317 C_3    4 0 -0.27000
   ATOM    4548 HCD2  LEU    318   -7.75464  -7.91803  14.79952 H_     1 0  0.09000
   ATOM    4549 HCD2  LEU    318   -8.10485  -9.33270  15.79871 H_     1 0  0.09000
   ATOM    4550 HCD2  LEU    318   -9.31410  -8.05348  15.62518 H_     1 0  0.09000
   ATOM    4551  N    GLY    319   -8.71770  -2.77439  16.71834 N_R    3 0 -0.47000
   ATOM    4552 HN    GLY    319   -8.69152  -2.87454  15.75858 H___A  1 0  0.31000
   ATOM    4553  CA   GLY    319   -8.48831  -1.42062  17.17743 C_3    4 0 -0.02000
   ATOM    4554 HCA   GLY    319   -9.23650  -1.16420  17.93092 H_     1 0  0.09000
   ATOM    4555 HCA   GLY    319   -8.65103  -0.75119  16.33306 H_     1 0  0.09000
   ATOM    4556  C    GLY    319   -7.14757  -1.08823  17.71950 C_R    3 0  0.51000
   ATOM    4557  O    GLY    319   -6.15276  -1.84709  17.63535 O_2    1 2 -0.51000
   ATOM    4558  OXT  GLY    319   -7.00093  -0.12662  18.51114 O_2    1 2 -0.67000
   45 FORMAT CONECT (a6,12i6)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using variable output in awk

Hi, I am trying to use variable output in awk to append a string to a word in a line. But that is not happening. Could you please help me on this. YouTube Video Tutorial: How to Use Code Tags and Format Posts @UNIX.com The below is the code #!/bin/ksh set -x src=/users/oracle/Temp... (2 Replies)
Discussion started by: pvmanikandan
2 Replies

2. Shell Programming and Scripting

awk - saving results of external script to variable.

So, I've been playing with speeding up some analysis we do by using multiple threads of awk (actually, mawk, but code-compatible as far as I use it) on multiple CPU cores. So, I have a big data file and I have several copies of exactly the same processor script, written in mawk. I also have a... (8 Replies)
Discussion started by: treesloth
8 Replies

3. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

Perl help - how to assign output of perl to variable

Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command ./ciscomgrtest.pl -r "show version" -h hosts.router and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies

5. Shell Programming and Scripting

help on awk---- need to assign the output of awk to a variable

hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb. i am doin this script, but it is throwing error.... #!/bin/ksh cd . | du -s | size = awk '{print $1}' if size >= 112000 then echo size high fi ERROR : (4 Replies)
Discussion started by: Nithz
4 Replies

6. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

7. Shell Programming and Scripting

Assign perl output to ksh shell variable

Hello, I am writing a ksh script on an AIX system. I need to get the date and time from a file into a variable. I found the following perl script from another post on this site and modified it slightly to output the format I need: perl -e '@d=localtime ((stat(shift)));... (4 Replies)
Discussion started by: swimp
4 Replies

8. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

9. UNIX for Dummies Questions & Answers

saving command output to a variable

Hello, I have a shell script containing a command string in the following format: command1 | command2 | cut -c9-16 The output from this is a record number (using characters 9-16 of the original output string) e.g. ORD-1234 I wish to save this value to a variable for use in later commands... (4 Replies)
Discussion started by: philjo
4 Replies

10. Shell Programming and Scripting

saving awk value in a bash array variable

hi all i am trying to save an awk value into an array in bash: total=`awk '{sum+=$3} END {print sum}' "$count".txt"` ((count++)) the above statement is in a while loop.. $count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.) i get the following error: ./lines1:... (1 Reply)
Discussion started by: npatwardhan
1 Replies
Login or Register to Ask a Question