I suppose this is a silly newbie Q, but I have a set of text I am inserting into a file using a sed cmd and before I insert, I want to ask the sed operation to move to add a carriage return first, and then place my new line.
Is there scope within the sed command to do this - i have tried "\n" as follows with obivous run-time errors:-
$cat fileToEdit | sed -e $lineToEnterNewText's/$oldline \n $newText/' > fileToEdit
Thanks
$ cat fileToEdit | sed -e "$lineToEnterNewText"' s/^\(.*\)$/\1\
'"$newText"'/' > fileToEdit
Some versions of sed recognize escape sequences:
echo tvparty |sed 's/\(tv\)\(party\)/\1\n\2/g'
For example, I'm using GNU sed...
In sed in match part of s/// escape sequence (\n) can be used, in replace part - only newline (as I've shown above)
I may have misunderstood, but I think you are correct - sed has a hard time matching newline, but it can insert a newline (depending on version, as I said before.) However, on second review, it looks like he may have wanted to add newline to the start of a line...
If we can remove sed, why not ' printf "\n$string" '?
If I didn't get it right this time, mea culpa.
ha? then we'll get 2 lines
Strange, neither of the ways work on my sed version..? although it does say in the info page - version 3.02 of GNU Sed.