October 21st, 2003, 10:25 PM
sed command problem
hi all. pls help.
i am using the sed command to substitute several text patterns in a file. my problem is, i want to replace the pattern with a new line. i cant seem to make \n work. here's an example. the patterns to be replaced with a next line are "abc", "def" and "hij".
qwertyabcuiop asdfgdefhjkl hijzxcvbnm
output file shoule be like this:
October 22nd, 2003, 07:19 AM
To my knowledge, \n doesn't work in sed. But you can spilt lines:
=> This is\(.*\)
echo "This is a test sentence" | \
sed -n 's/This is\(.*\)/This is\
=> This is\
Output patern. The \ after is is there for the linebreak, the \1 prints all that was captured with the \(.*\).