-   Programming (
-   -   string manipulation (

mannahazarika 12-28-2005 02:27 AM

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.

kshkid 12-28-2005 03:59 AM


>cat file
patternis this the requirement

>sed -e 's/pattern//' file
is this the requirement

Is this your question?

bigearsbilly 12-28-2005 04:25 AM

more correctly:


sed -e 's/.*pattern//'

mannahazarika 12-28-2005 07:56 AM

okay let me try them and i will inform that.
what if i want to print the info between 2 words/patterns.
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?

bigearsbilly 12-28-2005 08:01 AM

sed -e 's/.*pattern1\(.*\)pattern2.*/\1/'
should do it
or, same amount of typing
perl -pe 's/.*pattern1(.*)pattern2.*/$1/'

kshkid 12-28-2005 08:03 AM


echo "this is pattern1 and this is pattern2" | sed -e 's/.*pattern1//;s/pattern2//'

eddiebaby1023 12-31-2005 11:02 AM

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 08:51 AM.