Re: Search and replace with Unix commands
Re: Search and replace with Unix commands
- Subject: Re: Search and replace with Unix commands
- From: Tommy Bollman <email@hidden>
- Date: Thu, 5 Aug 2010 12:07:44 +0200
Hello.
Wouldn't this just do the trick in AppleScript ? I didn't sense that you meant that the text files where so big that this operation became too slow.
set AppleScript's text item delimiters to ""
set res to every paragraph of (read ("SomeHfsPathAsText" as alias))
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set res to res as text
log res
set res to swapText(res, (return & "John"), (return & "Harry"))
to swapText(theText, swapOut, swapIn)
(* This bit comes from Apple's own "Replace Text in Item Names" script
with some of the variables changed to make it a call-able handler *)
if the theText contains the swapOut then
-- replace target string using delimiters
set AppleScript's text item delimiters to the swapOut
set the text_item_list to every text item of theText
set AppleScript's text item delimiters to the swapIn
set the theText to the text_item_list as string
set AppleScript's text item delimiters to ""
end if
return theText
end swapText
On 5 Aug 2010, at 02:08, Hagimeno wrote:
> Hi,
>
> I need to search a string like '\rJohn' or '\nJohn' with another string
> All the unix command (Sed, Awk...) works one line at time and the separator is usually LF.
> How can I search and replace, not using pure AS because some text file are really bigger?
> I would like to use do shell script using cat to read the file and some Unix command to search empty line followed by my string and replace them with something else.
>
> Mark
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
Best regards
Tommy Bollman
--------------------------------------------------------------------------------------------------
Mollison's Bureaucracy Hypothesis:
If an idea can survive a bureaucratic review
and be implemented it wasn't worth doing.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden