在SED更换控制字符 [英] Replacing Control Character in sed
本文介绍了在SED更换控制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更换控制字符CTRL + A(SOH / ASCII 1)中出现的所有在Linux中的文本文件,这怎么能在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?
推荐答案
这可以通过做猫
与 -v
(等效于 - 显示 - 非打印
选项和管道到这一点 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/\t/g' > out
猫-v
将替换^ A,那么这将在 SED
相匹配并替换字符SOH
cat -v
would replace the SOH character with ^A, which would then be matched and replaced in sed
.
这篇关于在SED更换控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文