Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using 'sed' to alter file



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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden

References: 
 >Using 'sed' to alter file (From: Mark Walsh <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.