Sed: Adding new line after matching pattern | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Sed: Adding new line after matching pattern

UNIX for Dummies Questions & Answers


Tags
sed

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
MIA651 MIA651 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 10 April 2014, 12:11 PM EDT
Location: United States
Posts: 28
Thanks: 20
Thanked 1 Time in 1 Post
Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern:

The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off:


Code:
sed 'Wf a\'/n'/g'

Basically, I want to add a new line after occurrence of Wf. After the line Wf is in and not after Wf itself.
Sponsored Links
    #2  
Old 12-10-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 Posts

Code:
sed 's/Wf/&\
/g' file

or

Code:
sed 's/Wf/\
&/g' file

depending on how you want it.
Sponsored Links
    #3  
Old 12-10-2012
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 21 July 2014, 11:56 PM EDT
Location: India
Posts: 1,816
Thanks: 24
Thanked 519 Times in 498 Posts
\n would work with GNU sed:

Code:
sed 's/Wf/&\n/g' file

    #4  
Old 12-10-2012
MIA651 MIA651 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 10 April 2014, 12:11 PM EDT
Location: United States
Posts: 28
Thanks: 20
Thanked 1 Time in 1 Post
Thanks elixir_sinari but this is after Wf, I want a line appended after the line Wf occurs if you know what I mean.
Sponsored Links
    #5  
Old 12-10-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 Posts

Code:
sed '/.*Wf.*/s//&\
/' file

or

Code:
sed '/Wf/a\
' file

Sponsored Links
    #6  
Old 12-10-2012
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 22 July 2014, 3:37 PM EDT
Location: Amsterdam
Posts: 9,278
Thanks: 260
Thanked 2,302 Times in 2,065 Posts

Code:
sed '/Wf/s/$/\
/' file

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
sed - combination of line deletion and pattern matching jawsnnn UNIX for Dummies Questions & Answers 9 08-05-2012 01:41 PM
How to use sed to modify a line above or below matching pattern? sprinner Shell Programming and Scripting 7 07-18-2011 11:56 AM
SED Question: Search and Replace start of line to matching pattern DrivesMeCrazy Shell Programming and Scripting 3 03-18-2010 12:18 AM
sed find matching pattern delete next line aveitas Shell Programming and Scripting 2 12-22-2008 12:54 PM
SED - adding a new line after pattern eagercyber Shell Programming and Scripting 6 07-06-2008 11:06 AM



All times are GMT -4. The time now is 01:36 AM.