LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2006, 06:06 AM   #1
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Rep: Reputation: 15
Inputting with sed, based on matched pattern


Hi,

I want to know if you can input with sed but instead of specifing a line number like below I wan't to be able to insert based on a specific word or patttern.

Code:
10i\

This line will be inserted before each line
is this possible with sed or should I use AWK?

Thanks

Mike
 
Old 07-20-2006, 06:39 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
/match/ { i\
this
}
Code:
perl -pe 'print "THIS\n" if /match/'

Last edited by bigearsbilly; 07-20-2006 at 06:42 AM.
 
Old 07-20-2006, 06:47 AM   #3
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bigearsbilly
Code:
/match/ { i\
this
}
Code:
perl -pe 'print "THIS\n" if /match/'
Thansk Billy, the sed script was exactly what I was looking for, i figured it would be like AWK /pattern/ match but I wasnt using the curly brackets in my script.

Mike
 
Old 07-20-2006, 07:00 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
the good old curly brackets are a V. useful thing in sed
 
Old 07-20-2006, 08:47 AM   #5
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bigearsbilly
the good old curly brackets are a V. useful thing in sed
Hi, thanks again, how do you mean? a "V" like for encapsulation?

Mike
 
Old 07-20-2006, 08:49 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
no V. as in Very

just the stupid way I talk!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 07:17 AM
how to use the sed w option to redirect pattern match to file nickleus Linux - General 11 04-18-2006 09:34 AM
renaming text files based upon a pattern in their content Spacepup Linux - General 1 07-28-2005 02:43 PM
replacement with sed: replace pattern with multiple lines Hcman Programming 5 11-18-2004 08:40 AM
replacing pattern with sed produces double realos Programming 1 10-17-2002 09:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration