gawk-help

Giorgos Keramidas keramida at ceid.upatras.gr
Thu Mar 23 23:12:10 EET 2000


On Fri, Mar 24, 2000 at 03:58:31AM +0200, OLga+NaTaLia wrote:
> pos ginete me awk i me sed  ayto:
> 
> na psajw sta 9 prwta pedia enos text arxeiou plin tou prwtou, mia
> metabliti kai na mu typonei olokliri tin grammi an plirei tis
> proypo8eseis
> 
> i apla dior8wste me :
> 
> read inform        (dinw as poume "pedi")
> gawk -F^
>         ($2 ~ /"$inform"/) || ($3 ~ /"$inform"/) ||
>         ($4 ~ /"$inform"/) || ($5 ~ /"$inform"/) ||
>         ($6 ~ /"$inform"/) || ($7 ~ /"$inform"/) ||
>         ($8 ~ /"$inform"/) || ($9 ~ /"$inform"/)
> 
> { print $0; } ' arxeio

Thelei ligo prosoxi me ta dollaria ($), giati sto expression pou
egrapses parapano, poios kanei expand to /"$inform"/ p.x.?

An theleis kommati enos awk-script na to kanei expand to shell, duo
luseis uparxoun:

a) Grafeis to script sto command-line mesa se '' (apla quotes), alla
   prosexeis katallhla kommatia tou an einai ektos quotes, p.x.:

	awk '($2 ~ /'"$inform"'/ { print $0; }'

   auto mporei na odngnsei se paranoika quoting, eidika, an to
   sunduaseis me ta anapoda quotes, se entoles tou stul `pwd`.

b) grafeis se ena temporary arxeio ena awk script, kai meta kaleis tin
   awk me auto:

	cat <<EOF >/tmp/awk.$$.script.0
	\$2 ~ /$inform/		{print $0;}
	EOF
	# kaloume tin awk.
	awk -F^ -f /tmp/awk.$$.script.0 < arxeio
	# sbnvoume to temporary script
	rm -f /tmp/awk.$$.script.0

   antistoixa problimata exei ki auto, giati otidnpote metaju tis
   entolis "cat <<EOF" kai tou idiou tou EOF, to shell to kanei expand
   gia metablntes kai entoles mesa se back-quotes, `pwd`.

<flame bait>
Mia tritn lusn, gia na min trabas ta mallia sou ka8e fora pou jexnas ena
quote h bazeis anapodo quote eno den eprepe, einai na ma8eis perl :p
</flame bait>

Ciao,
- Giorgos Keramidas

--
linux-greek-users mailing list -- http://lists.hellug.gr




More information about the Linux-greek-users mailing list