Re: sed: escaping UNIX newlines
Re: sed: escaping UNIX newlines
- Subject: Re: sed: escaping UNIX newlines
- From: Gnarlodious <email@hidden>
- Date: Sun, 18 Jan 2004 20:00:54 -0700
Entity BJ Terry spoke thus:
>
--do shell script "tr -d '
>
--' " & "<" & inPOSIX & ">" & flipPOSIX -- remove Mac line returns
>
do shell script "cat " & inPOSIX & " > " & flipPOSIX
Ok, I see you've bypassed this part. It's supposed to sweep all Mac returns
from the file before anything else, it seems like further on in the stream
those returns get changed to UNIX returns and I don't know where.
This is a brute force method, actually the only place Mac returns will
appear is in the "Comments" field since users paste text in there. If
there's a regex solution to replace them with <br> that would be best.
Those returns are only a problem when sorting lines, since"sort" chops the
line at the bogus return. I can see them in pico as ^M (caretM) but
otherwise they're real elusive.
>
do shell script "sed -e 's|<tr>|\\
>
<tr>|g' " & ,
>
flopPOSIX & ">" & flipPOSIX -- every row is a line of cells
>
>
For the first fragment, the commented portion removes the line endings,
>
which makes your sed command work incorrectly, as far as I can tell.
>
You can change your sed command instead, but changing this part was
>
easier. Basically, sed operates only on lines, and the files didn't
>
have lines anymore.
The only way I could get that character in Applescript was typing +ctl;v-M
and it works as expected, removing Mac returns while leaving UNIX returns.
>
For the second fragment: sed doesn't support \n as newline, \n is taken
>
as a literal "n" instead. You have to escape an actual newline
>
character to put a newline in the replacement string.
I still can't get sort to work.
Can't I use ASCII codes instead? That would really simplify all this line
ending wrangling.
-- Gnarlie
>
> First off I want to thank those who helped me on this script, Chris
>
> Janton,
>
> BJ Terry and Michael Terry for excellent pointers.
>
> I've learned a lot, here is the script so far:
>
> <http://www.Gnarlodious.com/OSX/AppleScript/iTunes-iPage.scpt.html>
>
>
>
> If you copy and paste this script to run it erase the international
>
> character block as the export to HTML mangles them.
>
>
>
> The problem is that I need to make onelines out of all cells to use
>
> the sort
>
> command, for example any newline followed by <td> needs to be changed
>
> to
>
> only <td>. This leaves a newline before the <tr> so sort can work its
>
> magic
>
> and cw can count lines.
>
>
>
> As you can see I eradicated all newlines with tr and attempted to
>
> reinsert
>
> them with sed but I don't know if I'm doing it right. Is it an
>
> Applescript
>
> issue or can't sed do this?
>
>
>
> -- Gnarlie
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.