In article <[EMAIL PROTECTED]>,
Dale Scheetz <[EMAIL PROTECTED]> wrote:
>I've been trying to use sed to do some editing of simple characters from a
>large block of ascii text. The text has tabs that I wish to replace with
>spaces, and hyphonated words wrapped across linefeeds that I also wish to
>remove.
>
>For the tabs, I try the following:
>
>       sed -e 's/'\t'/ /g' <infile >outfile
>
>Which very cleanly places every t in the document with a space!??

Because of the quoting. Besides, you cannot use `\t' in a regexp. I think
that's a major oversight but, from the manpage of sed:

\c      Any backslash-escaped character c, except for `{',
               '}', `(', `)', `<',  `>',  `|',  and  `+'  matches
               itself.

So you can forget about \t. However you can ofcourse just enter a normal
tab with Control-V TAB. That will work though it's not obvious when you
read the code later on.

>For the hyphonation I try:
>
>       sed -e 's/-'\n'//g' <infile >outfile
>
>and although the file gets slightly smaller (I didn't try to find out just
>what had been removed) none of the hyphonated text is corrected.

The manpage of sed also says that each line is stripped from the newline,
put in the buffer, processed and then printed with a trailing newline.
Which means you cannot match or replace newlines. There may be a way
around it by using pattern space buffers etc but then you're talking about
programming in the sed language, something you might not want to do.


However generally you can use perl where you'd use sed, and it's more
powerful. You can do this if you like:

perl -p -e 's/-\n//' -e 's/\t/ /g' <infile >outfile

The '-p' is important to mimic sed's default (print) behaviour.

You might also want to look into fmt(1), which might be just what you're
looking for.

HTH

Mike.
-- 
 Miquel van Smoorenburg |  Studying to be a technomage   <*>
    [EMAIL PROTECTED]  | "May you live in interesting times"


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .

Reply via email to