enoxlisi?
Giorgos Keramidas
keramida at ceid.upatras.gr
Mon May 5 01:55:02 EEST 2003
On 2003-05-04 20:17, Aleksandros Paleos <apalaios at cs.teiath.gr> wrote:
> Ksero oti poli tha enoxlitheite me ayto pou rotao , alla opou kai ean
> epsaksa kai osous kai ean rotisa den mou brike kaneis apantisi. Psaxno
> na bro tin apantisi se mia ergasia kai den ksero se kammia periptosi
> ti lisi tis... Prospastho edo kai kati meres kano diafora, diabazo
> ksana kai ksana alla den mporo
Diabase to documentation ths getline() sunarthshs se kapoio awk manual.
Meta ksanadiabase to. Meta pali. Otan to exeis katalabei polu kala,
kane to idio gia tin split().
> I askisi leei ta eksis exoume 2 arxeia
> to ena onomazetai last
> kai exei tin parakato grammografisi
> Username tty day month date Time-in Time-out
> Kostas tt0 Sun Feb 27 13:04 17:21
> .....................................
O mailer sou h o editor sou exei kseskisei tis stiles.
> Exoume episis kai allo ena me to onoma allow me gromografisi
> Username tty day month date Time-in Time-out
> To arxeio ayto periexei tis ores pou mporei enas xristis na syndeetai
> sto systima mas. To zitoumeno loipon einai na grapsoume ena awk file
> pou pairnei san pedia eisodou ta 2 parapano kai an kapoios xristis
> prospathei na apoktisei prosbasi apo to sistima mas se ores i apo
> termatiko pou den epitrepontai kai na emfanizei ena minima sto
> diaxeiristi me to onoma toy xristi kai tin ora pou prospathise na mpei
> kai ti diarkeia paramonis toy
Kalh h askhsh alla den exei kamia praktikh xrhsimothta. Den einai kalo
na zhtas na sou kanoume emeis thn askhsh sou omws. To hint pou sou
petaksa parapano gia tin getline() prepei na einai arketo, an den einai
katse kai grapse kati, dokimase to, kai ustera rota mas pio sugkekrimena
pragmata.
> I parapano loipon einai i ekfonisi tis askisis. Skeftika arxika na
> kano to eksis na kano elegxous gia kathe xristi tin ora pou
> mpike-mpainei me tis ores tou arxeiou allow.
Auto einai aplos mia epanalhpsh ths ekfonhshs. POS skefthkes na to
kaneis auto?
> Kapou edo kollisa giati paratirisa sto awk oti otan allazei arxeio ta
> $1,$2 den synexizoun san noumera alla ksanarxizoun apo tin arxi.
Den xreiazetai na 'allakseis' arxeio:
The ``function'' getline sets $0 to the next input record from
the cur- rent input file; getline <file sets $0 to the next
record from file. getline x sets variable x instead. Finally,
cmd | getline pipes the output of cmd into getline; each call of
getline returns the next line of output from cmd. In all cases,
getline returns 1 for a successful input, 0 for end of file, and
-1 for an error.
> Etsi loipon den mporo na kano kammia sygkrisi toy typoy $2>=$9 .
> Boithiste me kati na katafero sas parakalo , oli i ypothesi mou
> thymizei prosetairistikous pinakes......
Ta $0, $1, ... $NF na ta afhseis isixa, okay? Den einai anagkh na
kaneis th zwh sou duskolh. Xrhsimopoihse tis getline() kai split() kai
tha exeis ena oraio tropo na diabaseis mia mia oles tis grammes tou
'allow' file sou. San ena mikro paradeigma gia auto pou ennow, to
parakato mikro awk programma typonei to .bashrc arxeio sou me ena polu
inefficient kai ilithio tropo, alla mporei na sou balei idees gia th
lush ths askhshs:
awk 'BEGIN {
while (getline bline<".bashrc") {
k = split(bline, bf);
for (i = 0; i < k; i++) {
printf "%s%s", bf[i], FS;
}
printf "\n";
}
}'
> Kai kati akoma sto awk file mou grafo
> BEGIN {a=FILENAME}
> {
> if (a!=FILENAME)
> {
> print "allaksa arxeio"
> a=FILENAME
> }
> ......klp klp
> me to pou grafo sto shell(bash)
> awk -f myawk last allow
> me ti mia mou grafei allaksa arxeio
> Giati to kanei ayto.
Polu aplo na katalabeis giati an deis ta parakato:
$ awk 'BEGIN {print FILENAME}' .bashrc
$ awk '{print FILENAME}' .bashrc | uniq
.bashrc
$
> Pisteyo oti prepei na douleyei kapos etsi afou to a einai sto BEGIN
> pairnei tin timi a=LAST
Otan ftiaxneis programmata den exei kamia apolutos shmasia h aksia auto
pou pisteueis. Mono auto pou ksereis sigoura :P
> Kanei itn sygkrisi LAST!=LAST kai den emfanizei tipota. Ayto to eixa
> grapsei giati ithela na do se poio simeio allazei to arxeio . Kai
> ontos otan allaksei to arxeio mou to grafei to minima. Mou to grafei
> loipon 2 fores synolika mia stin arxi arxi kai mia stin allagi tou
> arxeioy . Pos dikaiologeitai tin proti?
Koitazontas ton kwdika ths awk mporeis na eisai sigouros gia auto. H
logikh einai aplh. H awk(1) anoigei ena input arxeio mono otan auto
xreiazetai (p.x. otan ths dwseis na input file sto command line) akribos
th stigmh pou prospathei na diabasei ena neo `input record' kai blepei
oti den exei input file. Tote allazei kai thn timh tou `FILENAME'.
> Eyxaristo poly se osous kanane ton kopo kai diabasane mexri edo ,
> basika exo tromeri anagki apo boitheia, giati o kathigitis mou den
> einai synergasimos sto bathmo pou tha prepe.
Krima.
More information about the Linux-greek-users
mailing list