替换 sed 中的控制字符 [英] Replacing Control Character in sed
问题描述
我需要在 linux 中的文本文件中替换所有出现的控制字符 CTRL+A (SOH/ascii 1),这在 SED 中如何实现?
I need to replace all occurrences of the control character CTRL+A (SOH/ascii 1) in a text file in linux, how can this be achieved in SED?
推荐答案
这可以通过 cat
和 -v
(相当于 --show-非打印
选项并将其传送到 sed
中).
This can be done through cat
with the -v
(equivalently --show-nonprinting
options and piping this into sed
).
如果控制字符是标题的开始(SOH)字符(CTRL+A/ASCII 1),而我们想用制表符替换它,我们将执行以下操作:
If the control character the start of heading (SOH) character (CTRL+A / ASCII 1), and we want to replace it with a tab, we would do the following:
cat -v file | sed 's/^A/ /g' > out
cat -v
会将 SOH 字符替换为 ^A,然后在 sed
中匹配和替换.
cat -v
would replace the SOH character with ^A, which would then be matched and replaced in sed
.
这篇关于替换 sed 中的控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!