我一直在努力寻找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的追加模式
发布评论