Unix Shell - equivalent of grep -f in sed

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > June 2006 > equivalent of grep -f in sed





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author equivalent of grep -f in sed
naive_out_here

2006-06-29, 1:21 pm

Hi all,

I want to implement in sed what the following command does

grep -f file1 file2

what this basically does is, the contents of the file1 are taken as the
pattern which has to be searched for in file2

i tried something like
sed 's/file1/abc/g' <file2>file3

but instead of taking file1 as input it takes the literal string"file1"
as input and seraches for that.kindly help me out here.thanks in advance

Kenan Kalajdzic

2006-06-29, 1:21 pm

naive_out_here <mailsuds@gmail.com> wrote:
>
> I want to implement in sed what the following command does
>
> grep -f file1 file2
>
> what this basically does is, the contents of the file1 are taken as the
> pattern which has to be searched for in file2
>
> i tried something like
> sed 's/file1/abc/g' <file2>file3
>
> but instead of taking file1 as input it takes the literal string"file1"
> as input and seraches for that.kindly help me out here.thanks in advance


In the simplest case, you could do it this way:

sed "s/`cat file1`/abc/g" file2 >file3

However, if file1 contains characters which have special meaning in sed,
the solution won't be that simple.

--
Kenan Kalajdzic
devtakh

2006-06-29, 1:21 pm



for line in ` cate file1`
do
sed 's/$line/abc/g' file2
done


Kenan Kalajdzic wrote:
> naive_out_here <mailsuds@gmail.com> wrote:
>
> In the simplest case, you could do it this way:
>
> sed "s/`cat file1`/abc/g" file2 >file3
>
> However, if file1 contains characters which have special meaning in sed,
> the solution won't be that simple.
>
> --
> Kenan Kalajdzic


Loki Harfagr

2006-06-29, 1:21 pm

Le Thu, 29 Jun 2006 06:19:04 -0700, naive_out_here a écrit_:

> Hi all,
>
> I want to implement in sed what the following command does
>
> grep -f file1 file2
>
> what this basically does is, the contents of the file1 are taken as the
> pattern which has to be searched for in file2
>
> i tried something like
> sed 's/file1/abc/g' <file2>file3
>
> but instead of taking file1 as input it takes the literal string"file1"
> as input and seraches for that.kindly help me out here.thanks in advance


See the ideas in recent thread :
http://groups.google.com/group/comp...f37e459a45a2077

In John Savage post (and mine) I believe you'll find the
path were no one goes ;-)
Bill Marcum

2006-06-29, 1:21 pm

On 29 Jun 2006 06:19:04 -0700, naive_out_here
<mailsuds@gmail.com> wrote:
> Hi all,
>
> I want to implement in sed what the following command does
>
> grep -f file1 file2
>
> what this basically does is, the contents of the file1 are taken as the
> pattern which has to be searched for in file2
>

sed -f file1 file2
but the contents of file1 have to be sed commands.


--
War spares not the brave, but the cowardly.
-- Anacreon
Steffen Schuler

2006-06-29, 7:21 pm

naive_out_here wrote:
> Hi all,
>
> I want to implement in sed what the following command does
>
> grep -f file1 file2
>
> what this basically does is, the contents of the file1 are taken as the
> pattern which has to be searched for in file2
>
> i tried something like
> sed 's/file1/abc/g' <file2>file3
>
> but instead of taking file1 as input it takes the literal string"file1"
> as input and seraches for that.kindly help me out here.thanks in advance
>

sed 's@^.*$@/&/p@' file1 | sed -nf - file2

but observe that escaping of characters must be handeled correctly.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com