kano ta prota mou bimata....boithiste me parakalo
Giorgos Keramidas
keramida at freebsd.org
Sun Mar 30 21:34:01 EEST 2003
On 2003-03-30 15:15, Aleksandros Paleos <apalaios at cs.teiath.gr> wrote:
> Xaireto prospatho na matho na ftiaxno kapoia script files kai exo
> polla problimata , skeftika na apeythyntho se esas gia na me
> boithisete . Ean sas fainontai polles oi apories mou apantiste sas
> parakalo se opoies mporeite...
> Exyaristo poly
>
> Exo faei olo to proi prospathontas na grapso ena script file to
> opoio na antistrefei ta periexomena enos arxeiou kai na ta
> apothikeyei se ena allo Kateliksa se ayto to script file
>
>
> i=100 #tha prepei to arxeio dystyxos me mikrotero megethos apo 100 grammes
> while (test $i -gt 1)
> do
> #echo $i
> i=` expr $i - 1`
> tail +$i $1|head -1 >>$2 #epilegete kathe fora mono mia grammi
> done
PROS THEOU ANTHROPE MOU! Oxi scripts se csh...
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
Gia na kaneis auto pou les parapanw einai kati san auto to mikro
bash(1) script:
count=$( wc -l $filename | awk '{print $1}' )
for line in $( jot "${count}" "${count}" 1 ) ; do
head -"${count}" "${filename}" | tail -1
done
> Opos mporeite na deite ektelo mia epanalipsi i opoia kathe fora
> epilegei mia grammi ksekinontas apo 100 pros ta pano apo ti thesi
> 100 kai paei pros to 1. Oso kai ean fainetai parakseno ayto
> douleyei giati ean to arxeio mas den exei 100 grammes tote to tail
> +100 den epistrefei tipota...
Logiko :)
> Bebaia prospatho na bro enan tropo na metrao tis grammes tou protoy
> arxeiou gia na ekteleitai mono toses fores i epanalipsi...
count=$( wc -l filename | awk '{print $1}' )
> prospathisa na grapso kati se
> a=` expr wc -l file`
> alla den mou doulepse...
Trexeis to `expr' me parametrous:
expr wc -l file
Otidhpote einai se `...` backquotes, mporeis na to dokimaseis kai
ksexorista sto command line sou:
$ expr wc -l .procmailrc
expr: syntax error
Ara gi auto den sou paizei. Auto pou thes einai to expr na dei sto
command line tou to APOTELESMA tou wc -l, dhladh kati san:
$ expr `wc -l .procmailrc`
Auto den einai polu sosto omws, afou pali den petuxainei. Giati?
$ expr `wc -l .procmailrc`
expr: syntax error
As doume ti bgazei to `wc -l':
$ wc -l .procmailrc
198 .procmailrc
Hmmmm, logiko loipon pou apotugxanei to expr, afou to trexeis san:
$ expr 198 .procmailrc
> Ara me poion tropo mporo na metriso tis grammes enos arxeiou?
Me wc -l. Auto pou thes einai to apotelesma, kai malista mono ton
arithmo na to anatheseis se mia metablhth.
$ wc -l .procmailrc
198 .procmailrc
$ wc -l .procmailrc | awk '{print $1}'
198
$ count=` wc -l .procmailrc | awk '{print $1}' `
$ echo $count
198
$ unset count
> Yparxei parametros stin entoli ls pou na mou deixnei mono ta files?
Oxi, alla panta mporeis na paikseis me th grep kai thn awk:
$ ls -l /tmp
total 16
-rw------- 1 giorgos wheel - 3352 Mar 30 21:28 #mutt-gothmog-2167-24#
-rw-rw-rw- 1 giorgos wheel - 0 Mar 30 18:47 grkbd.lock
-rw------- 1 giorgos wheel - 1991 Mar 30 21:18 mutt-gothmog-2167-24
drwxr-xr-x 4 root wheel - 512 Mar 30 18:48 screens
drwx------ 2 giorgos wheel - 512 Mar 30 18:47 ssh-d00gBobE
$ ls -l /tmp | grep '^-'
-rw------- 1 giorgos wheel - 3352 Mar 30 21:28 #mutt-gothmog-2167-24#
-rw-rw-rw- 1 giorgos wheel - 0 Mar 30 18:47 grkbd.lock
-rw------- 1 giorgos wheel - 1991 Mar 30 21:18 mutt-gothmog-2167-24
$ ls -l /tmp | grep '^-' | awk '{print $10}'
#mutt-gothmog-2167-24#
grkbd.lock
mutt-gothmog-2167-24
> Prospatho na grapso ena programma pou na emfanizei ta periexomena
> enos arxeiou mono ean to periexomeno toy einai megalytero apo 10
> grammes
[ $(wc -l $filename) -gt 10 ] && cat $filename
> Episis psaxno na bro enan tropo gia to pos mporo na emfanizo mono ta
> login names kai ta home direcotries ton xriston pou exoyn syndethei
> sto sistima mou kapia apopsi?
Prepei epeigontws na deis pos paizei h awk:
$ awk -F: '{print $1,$6}' < /etc/passwd
root /root
sysop /root
daemon /root
operator /
bin /
...
> Kai telos prospatho na bro enan tropo na stelno ena minima se osous
> xristes exoun kanei log in
Panta uparxei h entolh who:
$ who
giorgos ttyv0 Mar 30 18:47
root ttyp1 Mar 30 19:12 (:0:S.0)
$ who | awk '{print $1}'
giorgos
root
$ for user in ` who | awk '{print $1}' `; do \
echo hello $user ; done
hello giorgos
hello root
- Giorgos
More information about the Linux-greek-users
mailing list