在sed中插入标签的正确方法是什么? [英] What is the proper way to insert tab in sed?

查看:405
本文介绍了在sed中插入标签的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sed中插入制表符的正确方法是什么?我正在使用sed将标题行插入流中.之后,我可能可以使用正则表达式替换某些字符以放入制表符,但是有更好的方法吗?

What is the proper way to insert tab in sed? I'm inserting a header line into a stream using sed. I could probably do a replacement of some character afterward to put in tab using regular expression, but is there a better way to do it?

例如,假设我有:

some_command | sed '1itextTABtext'

我希望第一行看起来像这样(文本由制表符分隔):

I would like the first line to look like this (text is separated by a tab character):

text    text

我已经尝试在上面的命令中用"\ t","\ x09","(制表符本身)替换TAB.我已经尝试过使用带双引号和不带双引号的方法,并且无法在文本之间插入制表符.

I have tried substituting TAB in the command above with "\t", "\x09", " " (tab itself). I have tried it with and without double quotes and I can't get sed to insert tab in between the text.

我正试图在SLES 9中做到这一点.

I am trying to do this in SLES 9.

推荐答案

您可以简单地正确使用sed i命令:

You can simply use the sed i command correctly:

some_command | sed '1i\
text    text2'

我希望很明显,在

的'text'和'text2'之间有一个制表符.在MacOS X(10.7.2)上,因此可能在其他基于BSD的平台上,我可以使用:

where, as I hope it is obvious, there is a tab between 'text' and 'text2'. On MacOS X (10.7.2), and therefore probably on other BSD-based platforms, I was able to use:

some_command | sed '1i\
text\ttext2'

sed\t转换为选项卡.

如果sed无法解释\t并在命令行中插入选项卡是一个问题,请使用编辑器创建Shell脚本并运行该脚本.

If sed won't interpret \t and inserting tabs at the command line is a problem, create a shell script with an editor and run that script.

这篇关于在sed中插入标签的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆