[英]Bash Script to seperate a line contains “^A”
My file contains a line like 我的文件包含一行
39=2^A40=1^A54=2
I want to get like this 我想要这样
39=2,40=1,54=2
How can iIseparate value if line contains ^A`` in Bash Script? 如果行在Bash脚本中包含^ A``,我如何分隔值?
With sed you can just swap out your ^A
delimiter with a comma: 使用sed,您只需用逗号替换^A
分隔符即可:
echo "39=2^A40=1^A54=2" | sed 's/\^A/,/g'
With awk
you can do: 使用awk
您可以执行以下操作:
echo "39=2^A40=1^A54=2" | awk 'BEGIN{FS="[\\^][A]";OFS=","}{$1=$1}1'
You can use sed
in this way: 您可以通过以下方式使用sed
:
echo '39=2^A40=1^A54=2' | sed 's/\^A/,/g'
39=2,40=1,54=2
if the ^A
s were literal strings, other answers should help. 如果^A
是文字字符串,则其他答案应该有所帮助。 Just accept one, and I am gonna remove this answer. 请接受一个,我将删除此答案。 If the answers didn't help you, you can try this: 如果答案对您没有帮助,则可以尝试以下操作:
all ^A
below, you should type in this way: Ctrl-V ctrl-A
所有下面的^A
,您都应该以这种方式输入: Ctrl-V ctrl-A
you mentioned "open it in vi", you can in vim do: 您提到“在vi中打开”,则可以在vim中执行以下操作:
:%s/^A/,/g
sed 's/^A/,/g' file
echo 39=2^A40=1^A54=2 | awk '{sub(/\^A40=1\^A/,",40=1,")}1'
39=2,40=1,54=2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.