I have a line with spaces in the start for example \" Hello world\". I want to insert this line to a specific line in a file. for example insert \" hello world\" to the next f
$ a=" some string " $ echo -e "hello\nworld" hello world $ echo -e "hello\nworld" | sed "/world/ s/.*/${a}.\n&/" hello some string . world
The . was added in the substitution above to demonstrate that the trailing whitepsaces are preserved. Use sed "/world/ s/.*/${a}\n&/" instead.
.
sed "/world/ s/.*/${a}\n&/"