I have a configuration file for solaris zones that I generate as part of another script but I need to move part of the text to the end of the file prior to execution and I'm having problems getting the syntax correct on the sed command.
The file looks like this:
create -b
set zonepath=/export/zones/fred
set autoboot=false
set ip-type=shared
add net
set address=1.1.1.1
set physical=nxge0
end
add net
set address=1.1.1.2
set physical=nxge7
end
add rctl
set name=zone.max-swap
add value (priv=privileged,limit=2147483648,action=deny)
end
add dedicated-cpu
set ncpus=2
end
add capped-memory
set physical=2G
end
The lines in bold need to be moved to the end of the file so I tried using the following command in sed but can't get it working.
sed '/rctl/,/end/{h;d};${g;p;}' /tmp/filename
It pattern matches the correct lines and deletes them but doesn't print them at the end of the file.
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
You should use the uppercase version of hold so that the line you took into hold buffer will not be overwritten by the next you take there.
Also the p is not needed when get the buffer.
sed '/rctl/,/end/{H;d};$g' infile
In the output I get an extra blank line - not sure where it comes from though.