I have a file as below I want to add ” at the end but only to lines ending as a string I gave sed -i ‘s/$/”,/’ filename but it adds quotes to end of all the lines. Desired output is Is there a way to achieve this? Answer You can use The ‘s/:”[^”]*$/&”/’ command means: :”[^”]*$ – matches a