Mailing Lists: Apple Mailing Lists

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

Using 'sed' to alter file



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.

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

do shell script "echo -n " & quoted form of TheFileName & " | tr -Cu
'[:alnum:]:' '-'"

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)

So far, the closest I have come to the first scenario is the following

sed -e '/StringA/,/StringB/  s/" & " " & "/" & "-" & "/g' < " & quoted form
of TheFile & ">  " & quoted form of thenewfile

But that only changes spaces, and changes too much of the text before and
after the "StringA" and "StringB"

With my limited knowledge of sed (and almost non-existent knowledge of
regular expressions), it's been a struggle to get past my current progress.
I am hoping that there is someone out there who can help me get this
working. I hope I have given enough information to describe my problem, but
if not, please let me know.

Thanks in advance

Mark

 _______________________________________________
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



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.