I'm trying to create a sed expression to add a new line before a media query, but if run the expression again then it should not add the new line twice.
Currently I can add a new line after a semicolon or after an opening bracket, but when I try to check that "@media" has to be after in order to add the new line then the expression do not work.
sed -e 's/\([;{]\)\(\|\)/\1\n\2/' styles.less
Also I can add a line before media query, preserve its indentation, but not able to detect if it is preceded by ";" or "{". I don't want duplicate new lines if the command is run twice.
sed -ie 's/\(\s*\)@media/\n\1@media/' estilos.less
Just in case, I'm using CSS comb (with ATOM), which does a lot of things for my LESS or SASS files, but does not create this newline before the media queries.
Thanks for your help.
s/old/new/, that is all. It's not the right tool for inserting lines before or after other lines and it's certainly not for anything more complicated like checking if a line already exists before inserting it before some regexp or string match. edit your question to include concise, testable sample input and expected output and you'll get a clear, simple awk answer.