I would like to insert text at the beginning and at the end of the specified line of the number, for example, I have this txt file:
apple banana orange pineapple
To insert at the beginning and end of the first line, I use:
while read -r line do sed "1i[text_insert]$line" > outputfile1 done < inputfile while read -r line do sed "1i$line[text_insert2]" > outputfile2 done < outputfile1
and I get:
[text_insert]apple[text_insert2] banana orange pineapple
And now I would like to add text to line number 2:
[text_insert]apple[text_insert2] [text_insert3]banana[text_insert4] orange pineapple
I tried to use the same thing, but this does not work, and all the other features that I found are to insert text as a new line before the specified line, and not add it to the specified line.
source share