SED插入行命令OSX [英] sed insert line command OSX

查看:201
本文介绍了SED插入行命令OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用sed来插入文本文件中的第三行,而且我在其他论坛中发现的语法是:

I'm trying to insert text to the third line in a file using sed, and the syntax I've found on other forums is:

sed -i '' "3i\ text to insert" file

当我用这个但是,我得到一个错误:

When I use this however, I get an error:

sed: 1: "3i\ text to insert": extra characters after \ at the end of i command

我似乎无法找出是什么原因造成的问题。我使用OSX,这就是为什么我有一个空''我的扩展。

I can't seem to figure out what is causing the problem. I'm using OSX, which is why I have an empty ' ' as my extension.

谢谢!

推荐答案

您应该直接把后一个换行符 \\

You should put a newline directly after the \:

sed '3i\
text to insert' file

这实际上是由 POSIX规范定义的行为。即GNU sed的事实,您可以指定文本将在同一行插入是一个扩展。

This is actually the behaviour defined by the POSIX specification. The fact that GNU sed allows you to specify the text to be inserted on the same line is an extension.

这篇关于SED插入行命令OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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