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

查看:28
本文介绍了在 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天全站免登陆