Re: Using 'sed' to alter file
Re: Using 'sed' to alter file
- Subject: Re: Using 'sed' to alter file
- From: Mark Walsh <email@hidden>
- Date: Thu, 06 Apr 2006 18:56:15 -0400
On 4/6/06 4:31 PM, "Björn Lundin" <email@hidden> wrote:
>
> 6 apr 2006 kl. 20.38 skrev Mark J. Reed:
>
> <comments removed>
>> undef $/;
>> $_ = <>;
>> my ($before, $changeme, $after) = /\A(.*StringA)(.*)(StringB.*)\Z/sm;
>> $changeme =~ s/[^a-zA-Z0-9:]/-/g;
>> $_ = $before . $changeme . $after;
>> ($before, $changeme, $after) = /\A(.*StringC[^\(]*\()([^\)]*)(\).*)\Z/sm;
>> $changeme =~ s/[^a-zA-Z0-9:]/-/g;
>> $_ = $before . $changeme . $after;
>> print;
> </comments removed>
>
> And people find Perl hard to read/understand ;-)
> (I do not doubt it will work though)
>
Not as hard to understand as could be expected, I can get the general gist
of what Mark's got going on. It's the regular expressions that baffle me
(and make it so unreadable to those who don't understand them), but that
would be the case with any other utility like sed or awk that can probably
do what I need to do.
I didn't make it clear in my original post, but I need to replace the text
in multiple occurrences throughout the document (the text between StringA
and StringB should only occur once, but there will be several instances of
StringC, and I need to replace the text between the parentheses after each
occurence. And the text will be different between each set of parentheses.)
>From what I can understand of the script (and I could very easily be wrong
about this) I don't think the Perl script, as supplied, will handle my
ommission.
A little bit more information about what I am trying to do. We get files
from one of our clients which are made available to their suppliers through
an online system. Unfortunately, this system does many things to 'damage'
these files, including stripping all Mac file types and creator types, which
I can fix easily. But the biggest problem is that it also changes the names
of the files, all non-alphanumeric characters become dashes. The postscript
files we receive contain links to many images, and since the images have
been renamed, the links no longer work. Since I cannot rename the files
because every dash in the file name could be just about any character, I'm
trying to change the postscript files to relink them to the renamed files.
My intention to use 'sed' was because I have used it for simple
substitutions before, and it seemed to me that it would be able to handle
the task I need it to. Perl is a bit more daunting to me, so I might feel a
bit intimidated if I have to make any changes to the script.
Thank you very much for your input, Mark and Björn. I greatly appreciate
everything I have learned from the people on this list.
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden