I want to change more than a line of a file. It is a CSS file and I want to swap out a section to another.
This is a snippet from the file:
/*** Debu
The sed syntax you show is not entirely accurate; if it worked, then you must have used:
sed -n '/aStyle.Landscape {/,/}/p'
to print the lines from 'aStyle.Landscape' to the closing brace.
If you want to replace that paragraph, then you can do:
sed '/aStyle.Landscape {/,/}/c\
MImAbstractKeyAreaStyle.Landscape {\
/*** Label Setttings ***/\
label-margin-top: 6.0mm;\
label-margin-left-with-secondary: +1;\
secondary-label-separation: 2;\
...\
}'
Note that each line in the replacement text except the last is followed by a backslash.
You might find it better to use a script file:
sed -f sed.script css.file
When I ran the script above, copied verbatim from this answer into a file 'xx', on the CSS fragment from the question (in 'xx.css') using sh xx < xx.css, the output I got was:
/*** Debugging ***/
draw-button-bounding-rects: false;
draw-button-rects: false;
debug-touch-points: false;
draw-reactive-areas: false;
}
MImAbstractKeyAreaStyle.Landscape {
/*** Label Setttings ***/
label-margin-top: 6.0mm;
label-margin-left-with-secondary: +1;
secondary-label-separation: 2;
...
}
MImAbstractKeyAreaStyle.Portrait {
You said you got everything on one line...I wonder how you ran the script? If everything was 'on one line', I wonder if you do something like:
output=$(sed ... file.css)
followed by:
echo $output
This would flatten everything to one line (think of it as minimization). The shape of the CSS would be preserved if you wrote instead:
echo "$output"
This question shows how the 'flattening' problem arose. There were two levels of shell interpretation (the shell that runs the su command, and the shell that is run by the su command), which is enough to give anyone a headache. Doubling up the backslashes might be sufficient, but I'd create a script and run that.