在AIX上使用sed的追加模式

编程入门 行业动态 更新时间:2024-10-07 23:17:51
本文介绍了在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的追加模式

本文发布于:2023-11-24 14:09:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625530.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   AIX   sed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!