I have a sed script that does insert a text line at a certain line.
Here's my sed script:
20i
- the line number\
- inserts into a new line line number has something in it.file - the file where the text is.
sed -i "20i \ import NewPage from './newpage/index'; " file
What I'm trying to achieve is: the ability to check if the keyword "NewPage" exists in the document -> than do not insert the sed line.
Any way to do this?
Thanks in advance, AT
You could use a combination of grep and your command and ||
in bash like this:
grep -c NewPage yourfile || sed -i "20i \ import NewPage from './newpage/index'; " yourfile
It works like this:
||
is executed