I am trying to get how N
option works in a Sed editor.
My goal is to change "System Administrator" to "Desktop User" in the "file01", while braking line and even in the last line.
Sed won't catch up with the last line because there would not be a next line. Another modification is necessary, adding for instance:
sed 's/System Administrator/Desktop User/'
, but this and:
sed 'System\nAdministrator/Desktop\nUser/'
toggles in an unexpected way (for me), such that one of the command stops working for the last line, or last two lines. This happened either using N
between the two or befor both of them.
I am using GNU Sed, version 4.4 .
#cat file01
The first meeting of the Linux System
Administrator's group will be held on Tuesday.
Another line
And here we have: System Administrator's Group as well.
1.System Administrator's group.
2.System Administrators Group.
3.System Administrators Group.
The first meeting of the Linux System
Administrator's group will be held on Tuesday.
System Administrators Group.
Case 1, both commands after N
# sed '
>N
>s/System\nAdministrator/Desktop\nUser/
>s/System Administrator/Desktop User/
> ' file01
The first meeting of the Linux Desktop
User's group will be held on Tuesday.
Another line
And here we have: Desktop User's Group as well.
1.Desktop User's group.
2.System Administrators Group.
3.Desktop Users Group.
The first meeting of the Linux System
Administrator's group will be held on Tuesday.
Desktop Users Group.
Case 2, sed 's/System Administrator/Desktop User/'
before N
.
# sed '
> s/System Adminitrator/Desktop User/
> N
> s/System\nAdministrator/Desktop\nUser/
> ' file01
The first meeting of the Linux Desktop
User's group will be held on Tuesday.
Another line
And here we have: System Administrator's Group as well.
1.Desktop User's group.
2.System Administrators Group.
3.Desktop Users Group.
The first meeting of the Linux System
Administrator's group will be held on Tuesday.
System Administrators Group.
This seemed weird to me, and could not figure out what was wrong. [Edit]: further detail.
I am looking for replacing "System Administrator" with "Desktop User". Also if a line ends with "System" and the next line starts with "Administrator", i would have them replaced accordingly with "Desktop" and "User". All of this has been taken from a book, but the output did not match what the book was stating. I ended up not knowing what went wrong. The only world i found to describe my problem was the precedence, i apologize, it seems that i was wrong.