![如何安装 gawk-csv(和 gawkextlib)?](https://linux22.com/image/169821/%E5%A6%82%E4%BD%95%E5%AE%89%E8%A3%85%20gawk-csv%EF%BC%88%E5%92%8C%20gawkextlib%EF%BC%89%EF%BC%9F.png)
有简单客观的安装方法CSV 扩展名gawk
?
尝试停下来..需要更多的一步
使用 UBUNTU 18 LTS。
wget -c http://ftp.gnu.org/gnu/gawk/gawk-5.0.1.tar.gz
(和gawk-5.0.1.tar.gz.sig
)gpg --verify gawk-5.0.1.tar.gz.sig gawk-5.0.1.tar.gz
错误:“使用 RSA 密钥 DF597815937EC0D2...无法检查签名:没有公钥”。tar xvzf gawk-5.0.1.tar.gz
cd gawk-5.0.1
sudo su
跑后./configure && make && make check && make install
...
... long long process
...
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib/gawk
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make install-data-hook
make[4]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
for i in filefuncs.la fnmatch.la fork.la inplace.la intdiv.la ordchr.la readdir.la readfile.la revoutput.la revtwoway.la rwarray.la time.la ; do \
rm -f /usr/local/lib/gawk/$i ; \
done
make[4]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
make[3]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
make[2]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
Making install in extras
make[1]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extras'
make[2]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extras'
make[2]: Nothing to be done for 'install-exec-am'.
/bin/mkdir -p '/usr/local/etc/profile.d'
.././install-sh -c -m 644 gawk.sh gawk.csh '/usr/local/etc/profile.d'
make[2]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extras'
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extras'
Making install in doc
make[1]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/doc'
make[2]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/doc'
make[2]: Nothing to be done for 'install-exec-am'.
/bin/mkdir -p '/usr/local/share/info'
.././install-sh -c -m 644 ./gawk.info ./gawkinet.info ./gawkworkflow.info '/usr/local/share/info'
install-info --info-dir='/usr/local/share/info' '/usr/local/share/info/gawk.info'
install-info --info-dir='/usr/local/share/info' '/usr/local/share/info/gawkinet.info'
install-info --info-dir='/usr/local/share/info' '/usr/local/share/info/gawkworkflow.info'
/bin/mkdir -p '/usr/local/share/man/man1'
.././install-sh -c -m 644 gawk.1 '/usr/local/share/man/man1'
make[2]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/doc'
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/doc'
Making install in awklib
make[1]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
make[2]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
/bin/mkdir -p '/usr/local/libexec/awk'
.././install-sh -c pwcat grcat '/usr/local/libexec/awk'
make install-exec-hook
make[3]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
/bin/bash ../mkinstalldirs /usr/local/share/awk
mkdir -p -- /usr/local/share/awk
for i in passwd.awk group.awk ./eg/lib/*.awk ; do \
progname=`echo $i | sed 's;.*/;;'` ; \
.././install-sh -c -m 644 $i /usr/local/share/awk/$progname ; \
done
make[3]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/awklib'
Making install in po
make[1]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/po'
installing ca.gmo as /usr/local/share/locale/ca/LC_MESSAGES/gawk.mo
installing da.gmo as /usr/local/share/locale/da/LC_MESSAGES/gawk.mo
installing de.gmo as /usr/local/share/locale/de/LC_MESSAGES/gawk.mo
installing es.gmo as /usr/local/share/locale/es/LC_MESSAGES/gawk.mo
installing fi.gmo as /usr/local/share/locale/fi/LC_MESSAGES/gawk.mo
installing fr.gmo as /usr/local/share/locale/fr/LC_MESSAGES/gawk.mo
installing id.gmo as /usr/local/share/locale/id/LC_MESSAGES/gawk.mo
installing it.gmo as /usr/local/share/locale/it/LC_MESSAGES/gawk.mo
installing ja.gmo as /usr/local/share/locale/ja/LC_MESSAGES/gawk.mo
installing ko.gmo as /usr/local/share/locale/ko/LC_MESSAGES/gawk.mo
installing ms.gmo as /usr/local/share/locale/ms/LC_MESSAGES/gawk.mo
installing nl.gmo as /usr/local/share/locale/nl/LC_MESSAGES/gawk.mo
installing pl.gmo as /usr/local/share/locale/pl/LC_MESSAGES/gawk.mo
installing pt.gmo as /usr/local/share/locale/pt/LC_MESSAGES/gawk.mo
installing pt_BR.gmo as /usr/local/share/locale/pt_BR/LC_MESSAGES/gawk.mo
installing sv.gmo as /usr/local/share/locale/sv/LC_MESSAGES/gawk.mo
installing vi.gmo as /usr/local/share/locale/vi/LC_MESSAGES/gawk.mo
installing zh_CN.gmo as /usr/local/share/locale/zh_CN/LC_MESSAGES/gawk.mo
if test "gawk" = "gettext-tools"; then \
/bin/mkdir -p /usr/local/share/gettext/po; \
for file in Makefile.in.in remove-potcdate.sin quot.sed boldquot.sed [email protected] [email protected] insert-header.sin Rules-quot Makevars.template; do \
.././install-sh -c -m 644 ./$file \
/usr/local/share/gettext/po/$file; \
done; \
for file in Makevars; do \
rm -f /usr/local/share/gettext/po/$file; \
done; \
else \
: ; \
fi
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/po'
Making install in test
make[1]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/test'
make[2]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/test'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/test'
make[1]: Leaving directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/test'
看来没问题。我的测试gawk --version
是4.1.1,现在是5.0.1。在上面的转储中我们可以看到make[4]: Entering directory '/home/admin_dq/transfer/AWK/gawk-5.0.1/extension'
,看来扩展库就在那里。
但现在原来的问题:我需要gawk-csv
,但它是“找不到命令”。
如何下载和安装 CSV 扩展吗?
我也尝试gawk -i csv
但错误“gawk:致命:无法打开源文件‘csv’进行读取(没有这样的文件或目录)”。
PS1:如何查看所有已安装的扩展列表? PS2:另一个指南说我需要跑rpmbuild
...
笔记
摘要:我需要的是工具,而不是学习黑客技术。
看起来该工具的 Linux 名称是gawk-csv
,但其主库的名称是gawkextlib
。
有两个相互冲突的指南,自述文件和安装 CSV 扩展。第一次提供唯一的下载。
PS:有6年前的问题在这里,但直到 2020 年才gawk-csv
推出 1.0.0 版本。
CSV 很重要
这是一个非常重要的扩展经典的AWK,因为通用的CSV文件不仅仅是“ a,b,c
”,AWK需要解析标准 CSV引号、转义行等
AWK 是完美的 (!),但它是不可能做到简单的 ETL 任务大 CSV 文件对于经典的 AWK,我们需要gawk-csv。
答案1
这个食谱现在对我有用。 YMMV。
更改DSTPATH
为您想要安装该扩展的位置。
我不建议安装任何事情手动进入系统目录(例如在 下/usr
);只能由发行版的工具(apt
、yum
等)管理。
DSTPATH=/tmp/baz
set -e
git clone https://git.code.sf.net/p/gawkextlib/code gawkextlib-code
cd gawkextlib-code/lib
autoreconf -i
./configure --prefix=$DSTPATH && make -j13 install
cd ../csv
autoreconf -i
./configure --prefix=$DSTPATH --with-gawkextlib=$DSTPATH && make -j13 install
export AWKPATH=$DSTPATH/share/awk AWKLIBPATH=$DSTPATH/lib/gawk
echo foo,bar,baz | gawk -i csv 'csvsplit($0,a){print a[2]}'
恕我直言,这一切都太过分了,并且有一千种可能失败的方式(缺乏适当的开发工具等)。
答案2
将有关安装到 /usr 的争论放在一边 - 我在构建 csv 库时发现的主要问题是 Makefile 没有指定运行链接库时定位 gawkextlib 所需的路径csv.so
。这意味着如果没有设置LD_LIBRARY_PATH
,即使构建和安装看起来成功,csv.so
也不会在运行时找到。libgawkextlib.so.0
结果是调用 gawk 时出现如下错误:
gawk: csv:15: fatal: load_ext: cannot open library `/usr/local/lib/gawk/csv.so' (libgawkextlib.so.0: cannot open shared object file: No such file or directory)
csv.so
gawk在 下查找/usr/local/lib/gawk/csv.so
,但csv.so
随后取决于libgawkextlib.so.0
哪个不在运行时库路径上。
我找不到configure
解决此问题的选项,最终再次从 make 输出运行链接行,但添加以下内容:
-Wl,-rpath,/usr/local/lib
-Wl
将以下选项直接发送到来自 的链接gcc
。
所以完整的行是:
gcc -shared -fPIC -DPIC .libs/csv.o .libs/csv_parser.o .libs/csv_convert.o .libs/csv_split.o .libs/csv_input.o .libs/strbuf.o .libs/awk_fieldwidth_info.o -L/usr/local/lib/ -Wl,-rpath,/usr/local/lib -L/usr/local/bin -lgawkextlib -g -O2 -Wl,-soname -Wl,csv.so -o .libs/csv.so
之后无需我操作库搜索路径csv.so
就可以找到:libgawkextlib.so.0
$ ldd csv.so
linux-vdso.so.1 (0x00007ffda36e6000)
libgawkextlib.so.0 => /usr/local/lib/libgawkextlib.so.0 (0x00007ffb8f535000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffb8f144000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffb8f93d000)
我在 Ubuntu 18.04 上的总过程如下,使用之前从源代码构建并安装在/usr/local/bin/gawk
.另请注意,我已经安装了所有构建工具,您可能需要使用apt
它来安装 gcc、autoconf、libtool 等 - 一个很好的起点是sudo apt install build-essential
.
获取来源:
git clone git://git.code.sf.net/p/gawkextlib/code gawkextlib
cd gawkextlib
构建 lib - 这里没什么特别的 -with-gawk
只是确保我们使用 gawk 的编译版本,而不是系统版本:
cd lib
autoreconf -i
./configure --with-gawk=/usr/local/bin/
make
sudo make install
使用库补丁构建 csv 扩展:
cd ../csv
autoreconf -i
./configure --with-gawk=/usr/local/bin/ --with-gawkextlib=/usr/local/lib/
make
gcc -shared -fPIC -DPIC .libs/csv.o .libs/csv_parser.o .libs/csv_convert.o .libs/csv_split.o .libs/csv_input.o .libs/strbuf.o .libs/awk_fieldwidth_info.o -L/usr/local/lib/ -Wl,-rpath,/usr/local/lib -L/usr/local/bin -lgawkextlib -g -O2 -Wl,-soname -Wl,csv.so -o .libs/csv.so
sudo make install
成功:
$ echo foo,bar,baz | gawk -i csv 'csvsplit($0,a){print a[2]}'
bar
最后提示 - 如果您遇到makeinfo
未安装的问题 - 在 ubuntu 上:
sudo apt-get install texinfo