Re: vi to do Shell Script
Re: vi to do Shell Script
- Subject: Re: vi to do Shell Script
- From: David Ferrington <email@hidden>
- Date: Wed, 04 Jan 2012 23:08:50 +0000
Or sed, replace
> set fixedText to do shell script "ruby -e \"puts " & quoted form of myText & ".gsub(/ +/,' ')\""
with
set fixedText to do shell script "sed -Ee 's/ +/ctrl-i/g' your_text_file_here"
replace your_text_file_here with the name of your text file, ctrl-i is the tab character - not happy with this, in Linux, a \t would translate into a tab, but it translates into a t in OSX because the sed version is so old
Note I haven't tried this, but the sed will work, the / +/ means one or more spaces (note, you can't use that in Linux or with basic regexp, you need the E option to allow that) - safer than two spaces, since you might not read it as 2 spaces
- David
Simplicity is the ultimate sophistication. -Leonardo da Vinci, painter, engineer, musician, and scientist (1452-1519)
On 4 Jan 2012, at 22:26, Stan Cleveland wrote:
> On Jan 4, 2012, at 2:00 PM, KOENIG Yvan wrote:
>
>> I want to replace every chunks of space characters embedded in a text file by a single TAB one.
>>
>> I was said tha the command vi :
>>
>> :%s/ */ctrl-i/g
>>
>> is able to do the trick.
>>
>> Alas, I have no idea of the way I may trigger it with a do Shell Script command.
>>
>> The scheme would be :
>>
>> set the_path to path:to:the:original:text:file
>> set the_path_Unix to posix path of the_path
>> set the_path_qUnix to quoted form of the_path_Unix
>> set edited_text to do Shel Script apply_vi_cmd to the_path_qUnix
>>
>> I hope that somebody will be able to give the correct incantation.
>
> Hi Yvan,
>
> How about some Ruby?
>
> set myText to "blah blah blah blah blah"
> set fixedText to do shell script "ruby -e \"puts " & quoted form of myText & ".gsub(/ +/,' ')\""
>
> Stan C.
>
> _______________________________________________
> 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
_______________________________________________
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