Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Sed: Adding new line after matching pattern

UNIX for Dummies Questions & Answers


Tags
sed

 
 
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: 19 April 2016, 1:01 PM EDT
Location: United States
Posts: 33
Thanks: 21
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: 29 November 2016, 6:07 AM EST
Location: India
Posts: 1,413
Thanks: 101
Thanked 497 Times in 474 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: 1 December 2016, 8:47 AM EST
Location: India
Posts: 1,966
Thanks: 30
Thanked 567 Times in 543 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: 19 April 2016, 1:01 PM EDT
Location: United States
Posts: 33
Thanks: 21
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: 29 November 2016, 6:07 AM EST
Location: India
Posts: 1,413
Thanks: 101
Thanked 497 Times in 474 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: 2 December 2016, 2:51 AM EST
Location: Amsterdam
Posts: 11,096
Thanks: 440
Thanked 3,105 Times in 2,747 Posts

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

Sponsored Links
 

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



All times are GMT -4. The time now is 08:15 PM.