awk help :)

Kyriacos Achilleos g9kyris at hotmail.com
Tue Apr 28 19:02:25 EEST 2009


Geia sas paidia. Graftika sto mailing list sas meta apo eisigisi kapiou filou. Exo mia aporia stin awk, an mporeite na me voithisete, dioti exo psaksei kai den vrisko ti lysi.

 

Exo ena file (file1) sto opoio mesa yparxoun 3 columns. To 1o column einai arithmoi (probabilities) kai ta alla 2 columns einai strings (1 leksi to kathe ena). Exo ena allo file (file2), to opoio einai san to file1 alla me 1 string column anti 2 (diladi synolo 2 columns).

Thelo tora apo to file1 na pernei to string tou 2ou column kathe grammis kai na psaxnei sto file2 gia na vrei tin leksi. Otan tin vrei thelo na perno to 1o column ($1) tis grammis, ton arithmo diladi pou einai prin ti leksi.

Sto telos, thelo na kanei output (se kainourio file) ta 3 columns tou file1 alla to column 1 me tous arithmous na kanei diairesi me ton antistoixo arithmo pou vrike apo to file2.

 

Akougetai sigoura polyploko alla eimai sigouros einai poly efkolo gia kapoio pou kserei kati parapano apo mena! Apla den ksero pos na kano search se allo file apo ena allo script. Den me noiazei na einai script i shell command synexomeno. Sas deinw ena paradeigma gia na sas einai pio ksekatharo.

 

file 1                                   file2


0.01 hello    hi                      0.04   hello

0.52 world   day                   0.02   night

0.23 night   football               0.03   world

 

to output -->

 

new file

 

0.01/0.04 hello    hi

0.52/0.03 world   day

0.23/0.02 night   football

 

exo grapsei liga pramata pano kato alla den ksero an to kano pio mperdemeno me afto ton tropo i oxi.

 

#!/bin/awk

BEGIN { RS="\n" }

word = $3;
unionprob = $1;


$(awk '$2 ~ $word { otherprob = $1 }' file2 )

 

#      ^ edo mou vgazei error..

 

END
{
printf "%.10f %s %s \n", $unionprob/$otherprob, $2, $3}

 

Tha to trexo logika me afto to command: awk -f code file1 > newfile 

 

Opoios mporei na voithisei, tha to ektimousa poly.

 

Efxaristw,

 

Kyriacos

 

y.g. sygnwmi gia ta gr-english:)

 

 

 

 

_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20090428/a9ad8dea/attachment.htm>


More information about the Linux-greek-users mailing list