awk help :)
Kyriacos Achilleos
g9kyris at hotmail.com
Tue Apr 28 21:13:22 EEST 2009
1000 efxaristw file! etsi opws mou to egrapses einai, akrivws. den eixa idea gia afto to command prin.
Na 'sai kala, kai pali efxaristw!
Kyriacos
> From: keramida at ceid.upatras.gr
> To: g9kyris at hotmail.com
> Subject: Re: awk help :)
> Date: Tue, 28 Apr 2009 20:14:51 +0300
> CC: linux-greek-users at lists.hellug.gr
>
> On Tue, 28 Apr 2009 18:02:25 +0200, Kyriacos Achilleos <g9kyris at hotmail.com> wrote:
> > 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.
>
> Αν είσαι σίγουρος ότι η σειρά των πεδίων στο file2 είναι αυτή που λες,
> όλο το παραπάνω γίνεται με μία εντολή `join' και λίγο awk στο τέλος:
>
> keramida at kobe:/tmp$ cat file1
> 0.01 hello hi
> 0.52 world day
> 0.23 night football
>
> keramida at kobe:/tmp$ cat file2
> 0.04 hello
> 0.02 night
> 0.03 world
>
> keramida at kobe:/tmp$ join -a 1 -e 1.0 -1 2 -2 2 -o 1.1,2.1,1.2,1.3 file1 file2
> 0.01 0.04 hello hi
> 0.52 0.03 world day
> 0.23 1.0 night football
>
> Για να δεις τι κάνει κάθε επιλογή της `join' που έβαλα παραπάνω, διάβασε
> το manpage του utility (`man join'). Μόλις φτάσεις σε αυτό το σημείο
> είναι ψιλο-προφανές πλέον τι χρειάζεται από το awk:
>
> keramida at kobe:/tmp$ join -a 1 -e 1.0 -1 2 -2 2 -o 1.1,2.1,1.2,1.3 file1 file2 | awk '{print $1/$2,$3,$4}'
> 0.25 hello hi
> 17.3333 world day
> 0.23 night football
>
> Αν τα word lists είναι και sorted από πριν, θα έχεις πιο καλά
> αποτελέσματα μάλλον:
>
> keramida at kobe:/tmp$ sort -k 2 < file1 > file1.tmp && mv file1.tmp file1
> keramida at kobe:/tmp$ sort -k 2 < file2 > file2.tmp && mv file2.tmp file2
> keramida at kobe:/tmp$ join -a 1 -e 1.0 -1 2 -2 2 -o 1.1,2.1,1.2,1.3 file1 file2 | awk '{print $1/$2,$3,$4}'
> 0.25 hello hi
> 11.5 night football
> 17.3333 world day
>
>
> --
> linux-greek-users mailing list -- http://lists.hellug.gr
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20090428/ab10baf1/attachment.htm>
More information about the Linux-greek-users
mailing list