[OT] sed question

Warren Block wblock at wonkity.com
Sun Mar 14 15:50:42 PST 2004


On Sun, 14 Mar 2004, Steven N. Fettig wrote:

> I can't figure out what the newline character is... I've tried \n \r &\,
> etc. with no avail.  I run the following:
>
> sed 's/[ ]/\n/g' my_test_text_document.txt

>From the sed man page:

"2.   The escape sequence \n matches a newline character embedded in
      the pattern space.  You can't, however, use a literal newline
      character in an address or in the substitute command."

I think this is a BSD thing, and sed on other systems does handle \n and
other literals in substitutions.  It's annoying enough that I just use
Perl instead.

perl -pe 's/ /\n/g' my_test_text_document.txt

which actually would be better as

perl -pe 's/\s./\n/g' my_test_text_document.txt

-Warren Block * Rapid City, South Dakota USA


More information about the freebsd-questions mailing list