Mail Archives: djgpp/1999/02/02/19:45:26
[Strictly spoken, this question is off-topic in the djgpp newsgroup.
But I'll answer anyway...]
In article <36B746EF DOT 1CEB499 AT nortelnetworks DOT com> you wrote:
> Hi,
> I'm having a problem understanding what I'm doing wrong.
> sed {s/\n/\t/ s/xyz/\n/} temp.txt | less
> I need to convert all the new lines to tab and then xyz to a new line.
I don't think you can do that with a command-line sed script. The first
part of the task would be
sed -e 's/$/ /' temp.txt
(whith a *literal* TAB character between the second and third '/'). For the
second part of your task, you will definitely need a sed command file, as
the necessary command contains a literal newline (not "\n", but actually
a new line to be started. In summary, you'll need a 'my.sed' script, like
----- my.sed ---
s/$/ /
s/xyz/\
/
----- my.sed ---
and use it as 'sed -f my.sed temp.txt'
> In addition it does not like \n in the pattern string and when \n is in
> the replace string I get a n in place of a new line.
> I thought I'd understood about regular expressions.
You may have, but you haven't heard that there are several different
types of regular expressions. sed only works on 'basic REs', and it
does not generally understand escape sequences like \n or \t. (It does
understand \n in some uses, but not in all possible ones...).
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -