Help with awk and scripting

August 12, 2010 at 16:05:49
Specs: Linux x86_64
Hi,
This is the first time I am working with awk and I am not familiar with any commands in it. But I managed to do most of my work just left with one more. Needing your help!

I have to extract only the matrix (written within []) from a text file. For example:
1JTJ_0006_ACGC_NPNP_A_12_15.pdb 0.61 0.54 [ 0.43 0.51 0.71 0.81]
1JTJ_0011_ACGC_NPNP_A_12_15.pdb 0.46 0.44 [0.37 0.30 0.42 0.70]

I have thousands of text files in a folder. I decided to use awk since I found one awk command on the internet to extract the substring within []. For each file read, after processing, the output should be stored in part of the filename_out.txt. I have almost completed the work. But I have the output as

0.43 0.51 0.71 0.81
0.37 0.30 0.42 0.70

I have to process this matrix further in matlab. So I just want square brackets at the end as,

[ 0.43 0.51 0.71 0.81
0.37 0.30 0.42 0.70 ]

Here is what I have done so far,

for f in *.pair.txt;do awk -v RS=[ -F] '/]/{split (FILENAME,d,".");}{print $1 >> d[1]"_out.txt"}' $f;done

I tried {print "[" > d[1]"out.txt"} in many places but dint work.

If there is anyother easy way of doing my task please let me know.

Thanks,
Sriji


See More: Help with awk and scripting

Report •

#1
August 13, 2010 at 01:34:46
I am not familiar with the script

Report •

#2
August 13, 2010 at 22:50:58
This is regarding building a dynamic filename: awk requires building a variable and then redirecting the print statement. This stub is an example:

echo ""| awk ' {
   d[1]="myfile"
   nfile=d[1]"_out.txt"
   print "stuff" >> nfile
} '
# end script

Let me now if you have any questions.


Report •
Related Solutions


Ask Question