我可以告诉xxd不要在其输出中打印任何换行符并将我的转储作为一条连续行吗?
[user@localhost] : ~ $ echo -n "this is a long line and xxd is going to take multiple lines to print it" | xxd -p
746869732069732061206c6f6e67206c696e6520616e6420787864206973
20676f696e6720746f2074616b65206d756c7469706c65206c696e657320
746f207072696e74206974
Run Code Online (Sandbox Code Playgroud)
小智 21
您需要的是 -c 选项。
# echo -n "this is a long line and xxd will print it as one line" | xxd -p -c 1000000
746869732069732061206c6f6e67206c696e6520616e64207878642077696c6c207072696e74206974206173206f6e65206c696e65
Run Code Online (Sandbox Code Playgroud)
以下是文档中的一些信息:
-c 列 | -cols cols 格式化每行八位字节。默认 16(-i:12,-ps:30,-b:6)。最大 256。
文档说“c”参数的最大值是 256,但我尝试了更大的值并且它起作用了。一探究竟:
# xxd -c 1000000 -p -l 1000000 /dev/urandom | wc -c
2000001
Run Code Online (Sandbox Code Playgroud)
在这里,我从 /dev/random 转储了 100 万个字节,并得到了一个 200 万 + 1 个字符的字符串。/dev/random 中的每个字节由 2 个字符表示,附加字节是最后的换行符。
小智 6
在xxd版本 2022-01-14 (随vim8.2.4088一起提供)或更高版本中,您现在可以使用值为 0 的 '-p' 和 '-c',如手册页中所述:
-c列|-cols列设置每行cols八位字节的格式。默认 16(
-i:12、-ps:30、-b:6)。最大值 256。 没有最大值 [原文如此]-ps。对于-ps,0 会产生一长行输出。
例如:
$ echo "Lorem Ipsum is simply dummy text of the printing and typesetting industry." | xxd -p -c0
4c6f72656d20497073756d2069732073696d706c792064756d6d792074657874206f6620746865207072696e74696e6720616e64207479706573657474696e6720696e6475737472792e0a
Run Code Online (Sandbox Code Playgroud)