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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-20-2006, 06:06 AM
|
#1
|
Member
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64
Rep:
|
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
|
|
|
07-20-2006, 06:39 AM
|
#2
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
Code:
/match/ { i\
this
}
Code:
perl -pe 'print "THIS\n" if /match/'
Last edited by bigearsbilly; 07-20-2006 at 06:42 AM.
|
|
|
07-20-2006, 06:47 AM
|
#3
|
Member
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64
Original Poster
Rep:
|
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
|
|
|
07-20-2006, 07:00 AM
|
#4
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
the good old curly brackets are a V. useful thing in sed

|
|
|
07-20-2006, 08:47 AM
|
#5
|
Member
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64
Original Poster
Rep:
|
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
|
|
|
07-20-2006, 08:49 AM
|
#6
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
no V. as in Very
just the stupid way I talk!
|
|
|
All times are GMT -5. The time now is 08:23 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|