Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 12-10-2012
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 7:53 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts

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

or

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

depending on how you want it.
Sponsored Links
    #3  
Old Unix and Linux 12-10-2012
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 23 August 2015, 9:36 AM EDT
Location: India
Posts: 1,892
Thanks: 27
Thanked 539 Times in 516 Posts
\n would work with GNU sed:

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

    #4  
Old Unix and Linux 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 Unix and Linux 12-10-2012
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 7:53 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts

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

or

Code:
sed '/Wf/a\
' file

Sponsored Links
    #6  
Old Unix and Linux 12-10-2012
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 4 September 2015, 7:16 PM EDT
Location: Amsterdam
Posts: 10,440
Thanks: 359
Thanked 2,771 Times in 2,476 Posts

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

Sponsored Links
Closed Linux or Unix Question

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
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 09:06 PM.