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.
10-30-2005, 01:09 PM
#1
LQ Newbie
Registered: Jul 2004
Posts: 8
Rep:
Delete text between key words : sed
I have a file called 'get.txt' as below
*******
cat get.txt
There are five birds three dogs ten chickens and two cats
*******
I need to delete all text from 'three' to 'chickens' including these 2 words like below:
*******
There are five birds and two cats
*******
can i do this using s/keyword1/keyword2/g
Any ideas on how to get this working??
ta,
jo
10-30-2005, 01:42 PM
#2
Member
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66
Rep:
Try:
Code:
sed "s/three.*chickens //g" get.txt
10-30-2005, 01:42 PM
#3
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Quote:
can i do this using s/keyword1/keyword2/g
Any ideas on how to get this working??
No, your idea won't work, it would replace the 1st keyword
with the second globally.
[edit]heh - beat by twenty seconds :}[/edit]
What you want to do is
s/keyword1.*keyword2//g
Cheers,
Tink
Last edited by Tinkster; 10-30-2005 at 01:44 PM .
10-30-2005, 01:45 PM
#4
Member
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66
Rep:
gg
10-31-2005, 02:20 PM
#5
LQ Newbie
Registered: Jul 2004
Posts: 8
Original Poster
Rep:
You guys are great ...thanks
i had to make a small change ...just a space between //
s/keyword1.*keyword2/ /g
thanks guys,
Jo
05-11-2011, 05:57 PM
#6
LQ Newbie
Registered: May 2011
Posts: 3
Rep:
what if
what if I wanted to do the same thing, but remove 's/keyword1.*keyword2//g' but leave keyword1 & keyword2 in place.
using keyword1 and 2 as references btw, cause I could easily use the words before&after each
05-11-2011, 06:14 PM
#7
LQ Newbie
Registered: May 2011
Posts: 3
Rep:
Quote:
Originally Posted by
ajbruscino
what if I wanted to do the same thing, but remove 's/keyword1.*keyword2//g' but leave keyword1 & keyword2 in place.
using keyword1 and 2 as references btw, cause I could easily use the words before&after each
quick example of my file
blahh............................
blahh..................
blahh.........................
blahh.................
I want to remove like s/[a-z].*$//g
that will remove the h at the end, how can I leave that....
05-11-2011, 06:22 PM
#8
LQ Newbie
Registered: May 2011
Posts: 3
Rep:
Quote:
Originally Posted by
ajbruscino
quick example of my file
blahh............................
blahh..................
blahh.........................
blahh.................
I want to remove like s/[a-z].*$//g
that will remove the h at the end, how can I leave that....
ok scratch that I figured out how to remove the ...... at the end
but still curious if I have a file that contains
the dog jumps over the stick
the cat crawls under stick
now removing between the.*stick leaving "the stick" behind
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 04:41 AM .
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