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.
|
 |
12-28-2005, 02:27 AM
|
#1
|
Member
Registered: Dec 2005
Posts: 41
Rep: 
|
string manipulation
suppose i want to find a pattern with grep, sed or awk,is there any way by which i can print what is in the right hand side of that pattern till the end of the line.
|
|
|
12-28-2005, 03:59 AM
|
#2
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Rep:
|
Code:
>cat file
patternis this the requirement
>sed -e 's/pattern//' file
is this the requirement
Is this your question?
|
|
|
12-28-2005, 04:25 AM
|
#3
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
more correctly:
Code:
sed -e 's/.*pattern//'
|
|
|
12-28-2005, 07:56 AM
|
#4
|
Member
Registered: Dec 2005
Posts: 41
Original Poster
Rep: 
|
okay let me try them and i will inform that.
what if i want to print the info between 2 words/patterns.
e.g.
let the following line exists in a file.
this is pattern1 and this is pattern2.
if i want to pring between pattern1 and pattern2 i.e. "and this is"
then how to do it?
|
|
|
12-28-2005, 08:01 AM
|
#5
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
sed -e 's/.*pattern1\(.*\)pattern2.*/\1/'
should do it
or, same amount of typing
perl -pe 's/.*pattern1(.*)pattern2.*/$1/'
Last edited by bigearsbilly; 12-28-2005 at 08:08 AM.
|
|
|
12-28-2005, 08:03 AM
|
#6
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Rep:
|
Code:
echo "this is pattern1 and this is pattern2" | sed -e 's/.*pattern1//;s/pattern2//'
|
|
|
12-31-2005, 11:02 AM
|
#7
|
Member
Registered: May 2005
Posts: 378
Rep:
|
Why do people always type the -e option when they're only using a single command? Must like typing, I guess. 
|
|
|
All times are GMT -5. The time now is 12:27 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
|
|