问题
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