0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Alma Linux 9.4 に gawk を入れてみた

Last updated at Posted at 2024-09-14

gawk も野良ビルドしてみた。

必要なツール、ライブラリのインストール

ライブラリディレクトリの設定

/usr/local 以下にインストールするので、この ld.so.conf が無いと見えない。

cat <<__EOF__>/etc/ld.so.conf.d/local.conf
/usr/local/lib/
__EOF__
ldconfig

コンパイル変数の設定

/usr/local 以下にインストールするので、この LDFLAGS が無いと見えない。

setenv CFLAGS '-mtune=native -march=native'
setenv LDFLAGS -L/usr/local/lib

m4 のインストール

curl https://repo.jing.rocks/gnu/m4/m4-1.4.19.tar.xz | tar xzf -
cd m4-1.4.19
./configure && make -j install
cd -

autoconf のインストール

m4 に依存しているので入れ直した方が良い。

curl https://repo.jing.rocks/gnu/autoconf/autoconf-2.72.tar.xz | tar xJf -
cd autoconf-2.72
./configure && make -j install
cd -

automke のインストール

autoconf に依存しているので入れ直した方が良い。

curl https://repo.jing.rocks/gnu/automake/automake-1.17.tar.xz | tar xJf -
cd automake-1.17
./configure && make -j install
cd -

bison のインストール

curl https://repo.jing.rocks/gnu/bison/bison-3.8.tar.xz | tar xJf -
cd bison-3.8
./configure && make -j install
cd -

gettext のインストール

curl https://repo.jing.rocks/gnu/gettext/gettext-0.22.5.tar.xz | tar xJf -
cd gettext-0.22.5
./configure && make -j install
cd -

flex のインストール

wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
tar xaf flex-2.6.4.tar.gz
cd flex-2.6.4
./autogen.sh
./configure && make -j install
cd -

gmp のインストール

mpfr の依存関係で必要

curl https://repo.jing.rocks/gnu/gmp/gmp-6.3.0.tar.xz | tar xJf -
cd gmp-6.3.0
./configure && make -j && make check && make -j install
cd -

mpfr のインストール

なくても良いが、gawk から読み込まれるみたいなので入れてみた。しかし、システムの方にリンクされてしまいましたとさ。→ ldconfig が必要でした。

curl https://repo.jing.rocks/gnu/mpfr/mpfr-4.2.1.tar.xz | tar xJf -
cd mpfr-4.2.1
./configure && make -j && make check && make -j install
cd -
  • ライブラリキャッシュの更新
ldconfig

gawk のインストール

curl https://repo.jing.rocks/gnu/gawk/gawk-5.3.0.tar.xz | tar xJf -
cd gawk-5.3.0
./configure && make -j && make check && make -j install
cd -

root では pma が動作しません。一般ユーザでチェックしてください。

最新機能 PMA とは?

PMA (Persistent-Memory gawk) の実行例

$ truncate -s 4096000 heap.pma
$ export GAWK_PERSIST_FILE=heap.pma
$ gawk 'BEGIN{myvar = 47}'
$ gawk 'BEGIN{myvar += 7; print myvar}'
54

通常なら 7 と表示されるところが 47 + 7 で、54 と表示される。
これは、実行が終了しても変数がヒープファイルに保存されているため、次に起動された gawk へ変数の内容が引き継がれているからである。
(作成するヒープファイルのサイズは 4KiB 単位である必要がある。)

変数はファイルに保存されているので切り替えて

$ truncate -s 4096000 heap.pmA
$ truncate -s 4096000 heap.pmB
$ alias pmA='GAWK_PERSIST_FILE=heap.pmA'
$ alias pmB='GAWK_PERSIST_FILE=heap.pmB'
$ pmA gawk 'BEGIN{print myvar=31}'
31
$ pmB gawk 'BEGIN{print myvar=12}'
12
$ pmA gawk 'BEGIN{print ++myvar}'
32
$ pmB gawk 'BEGIN{print --myvar}'
11

とすることもできる。

また、ハッシュを保存して簡単なデータベースのように扱うこともできる。

$ truncate -s 100M twain.pma
$ export GAWK_PERSIST_FILE=twain.pma
$ gawk ’{ts[$1]++}’ sawyer.txt						# ingest
$ gawk ’BEGIN{print ts["work"], ts["play"]}# query
92 11
$ gawk ’BEGIN{print ts["necktie"], ts["knife"]}# query
2 27

これの特徴は

  • 変数の内容をメモリ上に持たなくていい、余計なメモリ空間を用意しなくていい。(キャッシュから落ちると遅くなる)
  • スパースファイルなので書き込まれたデータは詰めて連続して書かれていてメモリキャッシュに載るときに小さなエリアで大きなデータが載る。
  • メモリを超えるサイズを扱うことができる。(メモリよりディスクの方が大きい場合)
  • ファイルの読み取りは一度で済ませて、後処理を試行錯誤することができる。

などがありそうですね。

詳細は↓を参照
https://web.eecs.umich.edu/~tpkelly/pma/pm-gawk_rev1.52_2022.08aug.16.pdf

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?