Using an append pattern sed on AIX

☆樱花仙子☆ 提交于 2021-02-11 16:11:29

问题


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.

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

1
2
3
4
5

And I want :

1
2
10
3
4
5

So that I can understand how it works on AIX.

On Linux, I can do

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

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 

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.

Thanks in advance,


回答1:


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'


来源:https://stackoverflow.com/questions/62280212/using-an-append-pattern-sed-on-aix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!