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"; 
1

1 Answer

This worked:

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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