Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-19-2012
Registered User
 
Join Date: Nov 2012
Posts: 10
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
Registered User
 
Join Date: Oct 2010
Posts: 2,102
Thanks: 64
Thanked 608 Times in 586 Posts
Try this:


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

Sponsored Links
    #3  
Old 11-19-2012
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,271
Thanks: 150
Thanked 722 Times in 695 Posts

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

    #4  
Old 11-19-2012
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,601
Thanks: 123
Thanked 717 Times in 600 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
Registered User
 
Join Date: Dec 2010
Posts: 522
Thanks: 45
Thanked 98 Times in 91 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

Tags
awk, perl, sed, tr

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 10:16 AM.