Add Text to Same Line Using Sed

Add Text to Same Line Using Sed

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

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

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.