在AIX上使用sed的追加模式 [英] Using an append pattern sed on AIX

查看:107
本文介绍了在AIX上使用sed的追加模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找sed模式,然后在AIX上附加一个字符.我在Linux上绝对没有问题,但是我真的不知道它应该如何在AIX上工作.

I have been struggling trying to find a pattern with sed and then append a character on AIX. I have absolutely no problem on Linux, but I really don't get how it is supposed to work on AIX.

非常简单:我有一个/tmp/test.txt:

Very simple : I have a /tmp/test.txt :

1
2
3
4
5

我想要:

1
2
10
3
4
5

这样我才能理解它在AIX上是如何工作的.

So that I can understand how it works on AIX.

在Linux上,我可以做

On Linux, I can do

sed -i '/2/ a 10\' /tmp/test.txt

有效.在AIX上,我知道我们必须解决,因为没有-i.但是即使在看了其他主题之后查找模式并附加在sed中

It works. On AIX, I know we have to do a work around because there's no -i. But even after looking at other topics like Find pattern and append in sed

我按照他们的例子尝试过

I tried that, following their example

cat /tmp/test.txt | sed '/2/i\10' > /tmp/test.temp
cat /tmp/test.txt | sed '\|"2"|i\10' > /tmp/test.temp 

可能还有其他数十种组合,但是我得到一些类似的东西,它无法解析,或者没有作为函数进行协调.或者可以运行它,但是当我查看test.temp时,什么也没发生.

And probably dozen of other combinaisons, but I get something like it can't be parsed, or it's not reconized as a function. Or it can be run, but when I look at test.temp, nothing happened.

预先感谢

推荐答案

AIX!sed不支持GNU扩展,仅支持严格的Posix格式(包括 a \ 部分).例如:

AIX!sed doesn't support GNU-extension, only the strict Posix-format (including the line-break after the a\ part). For example:

sed '/pattern/a\
insert after pattern
/pattern2/i\
insert before pattern2 - first line\
insert before pattern2 - second line'

这篇关于在AIX上使用sed的追加模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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