Add a newline after every period | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Add a newline after every period

Shell Programming and Scripting


Tags
awk, perl, sed, tr

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-19-2012
danbroz danbroz is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 15 May 2014, 3:32 PM EDT
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Add a newline after every period

I need to add a newline after every period.

Here is some sample text.
The mechanisms for this type of conditioning are probably the same in humans. According to PET scans on young adults, when pairing a stimulus with an airpuff produces a conditioned eye blink, activity increases in the cerebellum, red nucleus, and several other areas (Logan & Grafton, 1995). People who have damage in the cerebellum have weaker conditioned eye blinks, and the blinks are less accurately timed relative to the onset of the airpuff (Gerwig et al., 2005).
Sponsored Links
    #2  
Old 11-19-2012
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 22 October 2014, 5:31 PM EDT
Posts: 2,937
Thanks: 110
Thanked 930 Times in 870 Posts
Try this:


Code:
sed -e 's/\.  */.\n/g' -e 's/\.$/.\n/g' infile

Sponsored Links
    #3  
Old 11-19-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 4:20 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts

Code:
tr '. ' '\n' < filename

    #4  
Old 11-19-2012
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by bipinajith View Post
Code:
tr '. ' '\n' < filename

That will convert every period and space to a newline, not append a newline after the period.


Quote:
Originally Posted by Chubler_XL View Post
Try this:


Code:
sed -e 's/\.  */.\n/g' -e 's/\.$/.\n/g' infile

If that doesn't work for the OP, it's probably because \n in the replacement text is a GNU extension.

A more portable alternative:

Code:
sed 's/\. */.\
/g'

Regards,
Alister
The Following User Says Thank You to alister For This Useful Post:
danbroz (11-19-2012)
Sponsored Links
    #5  
Old 11-20-2012
Jotne's Avatar
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
With awk

Code:
awk '{gsub(/\. /,".\n");print}' infile

The Following User Says Thank You to Jotne For This Useful Post:
danbroz (11-21-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can I add a newline In a text file using Shell Script kpopfreakghecky Shell Programming and Scripting 1 08-29-2011 11:12 PM
How can I add a newline In a text file using Shell Script kpopfreakghecky UNIX for Dummies Questions & Answers 1 08-29-2011 11:10 PM
add newline in file after finding specific text jxh461 Shell Programming and Scripting 4 07-23-2009 12:31 AM
How to get rid of the last period (.) dannytrinh Shell Programming and Scripting 4 08-26-2008 07:48 AM
grep and sed to find a pattern and add newline ssikhar Shell Programming and Scripting 5 10-26-2004 05:32 PM



All times are GMT -4. The time now is 07:06 PM.