我怎么能输出空值终止在awk中字符串? [英] How can I output null-terminated strings in Awk?
问题描述
我的工作会被他人使用,可能摄取嫌疑字符串的shell脚本。它是根据各地的awk,所以作为一个基本的弹性措施,我想有AWK输出空值终止字符串 - 将接收从awk的数据,从而可以避免从包含空格或不经常出现的字符串一定量的破损的命令-in英文字符。
I'm working on a shell script that will be used by others, and may ingest suspect strings. It's based around awk, so as a basic resiliency measure, I want to have awk output null-terminated strings - the commands that will receive data from awk can thus avoid a certain amount of breakage from strings that contain spaces or not-often-found-in-English characters.
不幸的是,从基本的 AWK
的文件,我没有得到如何告诉awk将打印由ASCII空,而不是通过换行符结束的字符串。我怎么能告诉awk的,我想空终止字符串?
Unfortunately, from the basic awk
documentation, I'm not getting how to tell awk to print a string terminated by an ASCII null instead of by a newline. How can I tell awk that I want null-terminated strings?
AWK的版本可能用于:
Versions of awk that might be used:
[user@server1]$ awk --version
awk version 20070501
[user@server2]$ awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
[user@server3]$ awk -W version
GNU Awk 3.1.7
所以pretty多全家 awk的
版本。如果我们要巩固一个版本,它很可能会GNU awk的,但是对于所有版本的答案是受欢迎的,因为我可能会使其在所有这些awks的工作。哦,传统脚本。
So pretty much the whole family of awk
versions. If we have to consolidate on a version, it'll probably be GNU Awk, but answers for all versions are welcome since I might have to make it work across all of these awks. Oh, legacy scripts.
推荐答案
好吧,我知道了。
awk '{printf "%s\0", $0}'
或者使用 ORS
,
awk -vORS=$'\0' //
这篇关于我怎么能输出空值终止在awk中字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!