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: [OT] Shell scripting (2)



Thanks for the advice. What I'm trying to accomplish is a search/replace function for strings, not individual characters. From reading "man tr" I get the sense that tr operates strictly on characters. I'm sure the bit about the /tmp directory will be useful in future projects.

Marc [12/28/03 2:05:40 PM]


From: Stevan Reese <email@hidden>
Date: Sun Dec 28, 2003 11:19:13 AM America/Detroit
To: "Marc K. Myers" <email@hidden>, <email@hidden>
Subject: RE: [OT] Shell scripting (2)

Have a look at "tr", see #man tr
This line reads in the file contained in the variable "stylelistdoc" removes the carriage returns and replaces them with line feeds, then sends the output to /tmp/stylelist.iso while removing extra line > feeds.

do shell script "/usr/bin/tr \\\\'\\\\r' \\\\'\\\\n' < " & styleListdoc & " | /usr/bin/tr -s \\\\n > /tmp/stylelist.iso"

In the shell this would be "/usr/bin/tr '\r' '\n' < /filepath | /usr/bin/tr -s \n > /tmp/stylelist.iso"
The extra "\" remove Applescript's interference.

The other helpful thing this demonstrates is the use of the /tmp directory. You can stash data that is not final output here, then pick it up later in your script. I add a line to try and delete it on starting the script so that I don't have to clean up before running it again. If you don't the /tmp directory will get cleaned out daily anyway.
stevan

-----Original Message-----
From: Marc K. Myers [mailto:email@hidden]
Sent: Sat 12/27/2003 5:36 PM
To: email@hidden
Cc: Subject: [OT] Shell scripting (2)
Could someone point me in the right direction as to how to do a find
and replace on files in the Unix shell? What I'm doing now is reading
the file into a variable, using a TID handler to find and replace, and
writing the contents back to the file. Since this is such a common
need there is probably a much easier way to do it via shell scripting.
_______________________________________________
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.

References: 
 >RE: [OT] Shell scripting (2) (From: Stevan Reese <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.