I am trying to replace 1 line with 2 lines using sed in Debian and here is what I came up with:
sed -i 's/You are good/You are good\n You are the best/g' /output.txt
However, when I do this, sed kept complaining saying "unknown option to s".
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this if you’re in bash:
Strange, eh? But seems to work. Maybe sed can’t handle the newline correctly so it needs to be escaped with another backslash, thus
\\which will become a single\before going to sed.Also, note that you were not passing an extension to
-i.Edit
Just found another solution. As the newline needs to be escaped when passing to sed (otherwise it thinks it’s a command terminator) you can actually use single quotes and a return, just insert the backslash before entering the newline.