This is the code for appending string to a specific line number:
sed -e '1s/$/has/' -i testapend.txt
However, how would you be able to do the same thing but using a variable for the string and for the line number (int)?
I have so far tried inserting $variable
into the slashes and chucking in braces, but it either says unknown command or extra characters after the command.
linenum=3
append="Hello"
sed -e '/"$linenum"/ s/$/"$append"/' -i testapend.txt
I have also tried using sed -e "/$linenum/ s/$/$append/" -i testapend.txt and its still not working.
– Jerry Oct 31 '20 at 13:23sed -e "$linenum s/$/$append/"
(untested) – JJoao Oct 31 '20 at 13:43append
contains a/
, the s/// command becomes invalid syntax. – Paul_Pedant Oct 31 '20 at 14:08