Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blackxacto

macrumors 65816
Original poster
Jun 15, 2009
1,298
159
Middle TN
19,1 iMac, OSX 11.4: I can do this in Music w Apple scripts, but text documents in OS X either I have forgotten or need to learn how.
 
I am not sure what you mean: you want to remove a certain number of characters in the beginning of every sentence of a document? What kind of document format? If it is a plain text file (ASCII) you can use e.g sed in the terminal:

Bash:
sed 's/...//' file.txt

will remove the first three letters of each line in the document. Depending on your needs the sed command can easily extended, like removing a certain pattern or certain letters.
 
Thank you. What is the command telling the number of characters. I use terminal, but don’t know coding. Are you saying to insert the specific characters to delete by the ellipsis. I want to delete any number of characters at front.
 
Each dot is a single character. You can use eg
Code:
sed  's/.\{5\}//' file.txt
to remove first five characters, or you can use s/.....// for five. But that's by line, not by sentence, unless each sentence is on its own line.
 
Last edited:
  • Like
Reactions: synicalx1
Each dot is a single character. You can use eg
Code:
sed  's/.\{5\}//' file.txt
to remove first five characters, or you can use s/.....// for five. But that's by line, not by sentence, unless each sentence is on its own line.
In order for the document to include sentences on one line I have to insert breaks at end of all sentences, correct? I wish a command could recognize a sentence.
 
I wish a command could recognize a sentence.
That is a difficult condition to ensure. The simple idea would be to delete whatever number of characters following a period and space. However, you could have false positives (e.g., “The book by Dr. Seuss was…”).
 
That is a difficult condition to ensure. The simple idea would be to delete whatever number of characters following a period and space. However, you could have false positives (e.g., “The book by Dr. Seuss was…”).
If you have some knowledge beforehand it’s quite easy to exclude “Dr. “ from the processing - as well as define the end of a sentence incl. “!?”. @blackxacto: is this something you need often?
 
If you have some knowledge beforehand it’s quite easy to exclude “Dr. “ from the processing - as well as define the end of a sentence incl. “!?”.
Ha! Oops! I did forget about questions and exclamations. I was focused too much on the word “sentence“ and my period example.
 
If you have some knowledge beforehand it’s quite easy to exclude “Dr. “ from the processing - as well as define the end of a sentence incl. “!?”. @blackxacto: is this something you need often?
No, don't need often, just for this one project. It seems so easy in Music w a script.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.