Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Add a newline after every period

Shell Programming and Scripting


Tags
awk, perl, sed, tr

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-19-2012
danbroz danbroz is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 15 November 2015, 9:30 PM EST
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 Unix and Linux 11-19-2012
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 29 November 2016, 5:58 PM EST
Posts: 3,313
Thanks: 132
Thanked 1,122 Times in 1,045 Posts
Try this:


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

Sponsored Links
    #3  
Old Unix and Linux 11-19-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 Posts

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

    #4  
Old Unix and Linux 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 976 Times in 790 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-20-2012)
Sponsored Links
    #5  
Old Unix and Linux 11-20-2012
Jotne's Unix or Linux Image
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 212 Times in 202 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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-30-2011 12:12 AM
How can I add a newline In a text file using Shell Script kpopfreakghecky UNIX for Dummies Questions & Answers 1 08-30-2011 12:10 AM
add newline in file after finding specific text jxh461 Shell Programming and Scripting 4 07-23-2009 01:31 AM
How to get rid of the last period (.) dannytrinh Shell Programming and Scripting 4 08-26-2008 08:48 AM
grep and sed to find a pattern and add newline ssikhar Shell Programming and Scripting 5 10-26-2004 06:32 PM



All times are GMT -4. The time now is 03:42 AM.