Home > database >  Bash - put each sentence of a file on a diferent line
Bash - put each sentence of a file on a diferent line

Time:08-18

I need to read the length of each sentence on a text file.

I planned to separate each sentence on a different line and then read each line.

# LineSplitter

File="NameOfFile"

while read -r line; do
    # check the neght of $line
done <$file

I tried using tr to replace . for \n but this removes the . and does not work for questions.

Solutions for the LineSplitter?

It should be like this

Initial file:

SMS marketing is an excellent customer service tool because messages are delivered and read almost immediately — and there’s room for two-way communication. And SMS customer service can be scaled and automated. Plus, if you leverage this channel, your business will save money on phone service and customer service personnel training.


See a few templates for customer support messages below.

Final

SMS marketing is an excellent customer service tool because messages are delivered and read almost immediately — and there’s room for two-way communication.
And SMS customer service can be scaled and automated.
Plus, if you leverage this channel, your business will save money on phone service and customer service personnel training.
See a few templates for customer support messages below.

CodePudding user response:

Using sed

$ sed 's/\. /&\n/g' input_file
SMS marketing is an excellent customer service tool because messages are delivered and read almost immediately — and there’s room for two-way communication. 
And SMS customer service can be scaled and automated. 
Plus, if you leverage this channel, your business will save money on phone service and customer service personnel training. 
See a few templates for customer support messages below.
  • Related