[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[fol] Re: How to use shell variables in awk


Toshio HORI wrote:
> 
> In article <34C4C4C8.7914 _at_ jais.u-net.com>,
>         terry tashiro <tashiro _at_ jais.u-net.com> writes:
> terry> #!/bin/csh
> terry> set NAME="aaaa"
> terry> awk 'BEGIN { \
> terry> i=0;         \
> terry> }            \
> terry> /$NAME/ {    \
> terry> print $0;    \
> terry> }'           \
> terry>  input_file1
> terry> のように$NAMEをawkの中で展開してくれたら(もちろんこれでは展開
> terry> されません)いいのですが。
> 
> こんなん出ましたけど:)
> 
> % cat aaa
> #!/bin/sh
> NAME='aaa'
> awk '/'$NAME'/ { print $0; }' $1
> % chmod u+x aaa
> % cat bbb
> 1:a
> 2:aa
> 3:aaa
> 4:aaaa
> 5:aaa
> 6:aa
> 7:a
> % ./aaa bbb
> 3:aaa
> 4:aaaa
> 5:aaa

すっきりしてていいと思います。ありがとうございます。

tashiro

この情報があなたの探していたものかどうか選択してください。
yes/まさにこれだ!   no/違うなぁ   part/一部見つかった   try/これで試してみる

あなたが探していた情報はどのようなことか、ご自由に記入下さい。特に「まさにこれだ!」と言う場合は記入をお願いします。
例:「複数のマシンからCATV経由でipmasqueradeを利用してWebを参照したい場合の設定について」