I have a file that looks similar to this:
module.exports = {
blank: {
area: 'frontend',
name: 'Magento/blank',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
'css/email',
'css/email-inline'
],
dsl: 'less'
},
backend: {
area: 'adminhtml',
name: 'Magento/backend',
locale: 'en_US',
files: [
'css/styles-old',
'css/styles'
],
dsl: 'less'
}
};
I need to add another entry inside module.exports
. I use vim inside a bash script in the following way:
THEME_CONFIG="\r $LOWERCASE_THEME_TITLE: {\r
area: 'frontend',\r
name: '$ESCAPED_THEME_PATH',\r
locale: 'en_US',\r
files: [\r
'css\/styles-m',\r
'css\/styles-l'\r
],\r
dsl: 'less'\r
}\r
"
vim -c "%s/}\n/},$THEME_CONFIG\n/|wq" dev/tools/grunt/configs/themes.js
This works fine apart from the fact that I do not want to use \r
as it seems to be breaking grunt. I would like to use \n
instead, but if I replace \r
in the code above with \n
it does not work (THEME_CONFIG
has no line breaks).
I have tried \\n
, $'\n'
but all I get is one line.
sed
(or maybeawk
)\n
in a search pattern is a newline, but when used in a replacement pattern, it is a NULL character. Why this is the case I do not know, but the docs do say to use\r
or equivalently<CR>
/^M
; the latter of which you can insert by pressingCtrl+V
Enter
. Anyway, I agree with statox in thatsed
orawk
would be a better choice for this, seeing as how you're only running a substitute command. You wouldn't have to deal with this quirk and could just use\n
:)\n
is NULL in replacements.