How can I use a variable to find a pattern and then add a text, in the same line, after that pattern?

I tried this but it didn't work:

sed -i "/$node_number/ i mytext" "$filepath.csv";
  • 3
    Hello and welcome to AskUbuntu. Please edit your question to include a minimal example of your input (CSV file) and desired output. – steeldriver Apr 5 '19 at 23:44

This worked:

sed -i "s/$node_number/&mytext/" "filepath.csv";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.