Hi, I will try to answer each of your questions as best I can…
I have created a text file on my desktop containing this line - “line one.line two.line three.line four”
Replacing all instances of ‘.’ with ‘. [newline];’ would result in:-
line one.
;line two.
;line three.
;line four
The problem with trying to use sed to replace the ‘.’, is that ‘.’ is a special character used by sed to match any single character!
The shell command (Terminal) I used to get this was:-
sed ‘s_[.]_.!;_g’ <Path/to/Desktop/Untitled.txt | tr ‘!’ ‘\n’
I have used the _ as a delimiter here, rather than / (personal preference) and have had to enclose the ‘.’ in the square brackets [.] telling sed to match exactly this character and replace every instance to ‘.!;’. I have then used the shell command ‘tr’ (translate characters) to convert the ‘!’ to a new line ‘\n’ (If your text is likely to contain the ‘!’ character, you will have to find another unique character)
This in an Applescript would look like this:-
set txtF to POSIX path of (choose file with prompt "Choose a file")
do shell script "sed 's_[.]_.!;_g' <" & txtF & " | tr '!' '\\n' > ~/Desktop/converted.txt"
Note that the last ‘\n’ of the tr has had the ‘' escaped (’\')
To select a file to perform this command on, in the terminal, you simply have to provide the path to that file:-
/Users/your_username/Desktop/Untitled.txt
So, as in the Applescript above you can give the first sed command
sed ‘s_[.]_.!;_g’
provide the path to the file you want to run this command on
</Users/your_username/Desktop/Untitled.txt
then add the tr after a ‘pipe’ ‘|’
| tr ‘!’ ‘\n’
resulting in
sed ‘s_[.]_.!;_g’ </Users/your_username/Desktop/Untitled.txt | tr ‘!’ ‘\n’
I could not work out how to tell sed to generate a new line, hence why I used tr!
I hope this helps!