Example to use ‘sed’ to extract information from text file.
This example could get handler name and the code from a file.
There is 3 examples of different handlers that you could see in the log.
And have 2 examples of tag and comment.
Save this file as text file 'handlerTest.txt on your desktop.
-- Sample of handler library
on handler1()
-- some code...
end handler1
on handler2:_theString withParams:_theParams
-- some code 123...
end handler2:withParams:
on handler3(_theString,_theParams)
-- some code abc...
end handler3
--[tag:string1]
on handler4()
-- some code...
end handler4
--[comment:method1]
on handler5()
-- some code...
end handler5
This AS Script will ask for a file… pick the above file you have saved on your desktop.
set thePath to POSIX path of (path to desktop) & "handlerTest.txt"
log (my sedText:thePath Pattern:"/on handler1/,/end handler1/p")
log (my sedText:thePath Pattern:"/on handler2/,/end handler2/p")
log (my sedText:thePath Pattern:"/on handler3/,/end handler3/p")
log (my sedText:thePath Pattern:"/tag:string1/,/end/p")
log (my sedText:thePath Pattern:"/comment:method1/,/end/p")
on sedText:_thePath Pattern:_regExp
do shell script "cat " & quoted form of _thePath & " | sed -n '" & _regExp & "'"
end sedText:Pattern: