Re: Using 'sed' to alter file
Re: Using 'sed' to alter file
- Subject: Re: Using 'sed' to alter file
- From: Doug McNutt <email@hidden>
- Date: Thu, 6 Apr 2006 13:12:27 -0600
This is a job for Super - - er - - perl. You will not regret learning it.
At 13:48 -0400 4/6/06, Mark Walsh wrote:
>I am fairly new to shell scripting, but have been picking up bits and pieces
>here and there. Now I have a task which I'm having a little trouble working
>out.
# Begin untested code.
#! /usr/bin/perl
While (<INPUT>)
{
>I need to change all characters which are not alphanumeric or ":" in certain
>portions of a document to a dash "-". In other scripts where I have to
>change file names similarly, I have used the following
s/:(\d+):/-$1-/g;
>And that works well. In the documents I need to change, I need to change the
>characters that are between (but not including) "StringA" and "StringB" and
>also all of the characters between (but not including) the first set of
>parentheses after "StringC" (there are an unknown amount of characters
>between "StringC" and the parentheses)
s/$StringA.*?$StringB/$StringA$your_replacement$StringB/;
s/$StringC(.*?)\([^)]*\)/$StringC$1\($your_replacement\)/g
# But that's not so clear in your description.
print OUTPUT;
}
>With my limited knowledge of sed
Forget it.
> (and almost non-existent knowledge of regular expressions),
perl's have become the standard of the world.
You can write out the script into a temp file with AppleScript and then execute it with a single line in Do Shell Script or you can create the script with a text editor. Some changes required if line ends can occur between the string segments. () characters need to be escaped and that's probably also true of sed.
--
-->The Creator is the God who provided the void and the rules that matter and energy must live by in order to exist in it. Intelligent designers and engineers create useful stuff while abiding by the rules.<--
_______________________________________________
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