<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
1000 efxaristw file! etsi opws mou to egrapses einai, akrivws. den eixa idea gia afto to command prin.<BR>
<BR>
Na 'sai kala, kai pali efxaristw!<BR>
<BR>
Kyriacos<BR>
<BR>
<BR><BR> <BR>> From: keramida@ceid.upatras.gr<BR>> To: g9kyris@hotmail.com<BR>> Subject: Re: awk help :)<BR>> Date: Tue, 28 Apr 2009 20:14:51 +0300<BR>> CC: linux-greek-users@lists.hellug.gr<BR>> <BR>> On Tue, 28 Apr 2009 18:02:25 +0200, Kyriacos Achilleos <g9kyris@hotmail.com> wrote:<BR>> > Geia sas paidia. Graftika sto mailing list sas meta apo eisigisi<BR>> > kapiou filou. Exo mia aporia stin awk, an mporeite na me voithisete,<BR>> > dioti exo psaksei kai den vrisko ti lysi.<BR>> ><BR>> > Exo ena file (file1) sto opoio mesa yparxoun 3 columns. To 1o column<BR>> > einai arithmoi (probabilities) kai ta alla 2 columns einai strings (1<BR>> > leksi to kathe ena). Exo ena allo file (file2), to opoio einai san to<BR>> > file1 alla me 1 string column anti 2 (diladi synolo 2 columns).<BR>> ><BR>> > Thelo tora apo to file1 na pernei to string tou 2ou column kathe<BR>> > grammis kai na psaxnei sto file2 gia na vrei tin leksi. Otan tin vrei<BR>> > thelo na perno to 1o column ($1) tis grammis, ton arithmo diladi pou<BR>> > einai prin ti leksi.<BR>> ><BR>> > Sto telos, thelo na kanei output (se kainourio file) ta 3 columns tou<BR>> > file1 alla to column 1 me tous arithmous na kanei diairesi me ton<BR>> > antistoixo arithmo pou vrike apo to file2.<BR>> ><BR>> ><BR>> > Akougetai sigoura polyploko alla eimai sigouros einai poly efkolo gia<BR>> >> kapoio pou kserei kati parapano apo mena! Apla den ksero pos na kano<BR>> > search se allo file apo ena allo script. Den me noiazei na einai<BR>> > script i shell command synexomeno. Sas deinw ena paradeigma gia na<BR>> > sas einai pio ksekatharo.<BR>> <BR>> Αν είσαι σίγουρος ότι η σειρά των πεδίων στο file2 είναι αυτή που λες,<BR>> όλο το παραπάνω γίνεται με μία εντολή `join' και λίγο awk στο τέλος:<BR>> <BR>> keramida@kobe:/tmp$ cat file1<BR>> 0.01 hello hi<BR>> 0.52 world day<BR>> 0.23 night football<BR>> <BR>> keramida@kobe:/tmp$ cat file2<BR>> 0.04 hello<BR>> 0.02 night<BR>> 0.03 world<BR>> <BR>> keramida@kobe:/tmp$ join -a 1 -e 1.0 -1 2 -2 2 -o 1.1,2.1,1.2,1.3 file1 file2<BR>> 0.01 0.04 hello hi<BR>> 0.52 0.03 world day<BR>> 0.23 1.0 night football<BR>> <BR>> Για να δεις τι κάνει κάθε επιλογή της `join' που έβαλα παραπάνω, διάβασε<BR>> το manpage του utility (`man join'). Μόλις φτάσεις σε αυτό το σημείο<BR>> είναι ψιλο-προφανές πλέον τι χρειάζεται από το awk:<BR>> <BR>> keramida@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}'<BR>> 0.25 hello hi<BR>> 17.3333 world day<BR>> 0.23 night football<BR>> <BR>> Αν τα word lists είναι και sorted από πριν, θα έχεις πιο καλά<BR>> αποτελέσματα μάλλον:<BR>> <BR>> keramida@kobe:/tmp$ sort -k 2 < file1 > file1.tmp && mv file1.tmp file1<BR>> keramida@kobe:/tmp$ sort -k 2 < file2 > file2.tmp && mv file2.tmp file2<BR>> keramida@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}'<BR>> 0.25 hello hi<BR>> 11.5 night football<BR>> 17.3333 world day<BR>> <BR>> <BR>> --<BR>> linux-greek-users mailing list -- http://lists.hellug.gr<BR><br /><hr />Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! <a href='http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us' target='_new'>Try it!</a></body>
</html>