bing
1
hi,
i'm using egrep -i to search thru some text files for keywords (also stored in a file).
egrep does wildcard search aka %keyword%
as long as the keyword is found, it will be spool to a file
meaning if keyword is 'xyz'
123 aabgdggjxyzslgj
124 xyzgjksgjd
returns
123 aabgdggjxyzslgj
124 xyzgjksgjd
how do i make egrep search for keyword% only.
meaning if keyword is 'xyz'
123 aabgdggjxyzslgj
124 xyzgjksgjd
return only '124 xyzgjksgjd'
Can i add some indication to egrep in the keyword too? i tried egrep -i '^xyz' but in vain
Can't you place a space before the pattern like this?
egrep ' xyz' file
Post a more realistic example and the desired output.
bing
5
here it goes:
keyword file contains
xyz
abc
compressed data file (file1.gz)contains
p1 123 ljojeojo
p2 124 ighsphabc
p3 125 xyzskjkejhoj
p4 126 jorjojojojojo
p5 127 XYZrgjeojho
p6 128 gigsekxyz
i first read the keyword file
then using gzcat "file1.gz" | egrep -i $(searchitem) >> file1.out
to return
p3 125 xyzskjkejhoj
p5 127 XYZrgjeojho
by putting a '^xyz' can return results only if the 1st 2 columns are not present.
I don't see why Franklin's solution should not work.
f1 is the pattern list, f2 the file to search in:
$> while read F1; do grep -i " $F1" f2; done < f1
p3 125 xyzskjkejhoj
p5 127 XYZrgjeojho
egrep -i " $(searchitem)" >> file1.out
or
egrep -i "[ \t]$(searchitem)" >> file1.out
From your given input we could try..
egrep -i '[0-9][0-9]* xyz*'
bing
9
thanks for all the input,
this will do 'xyz' but for 'abc'
i would like to do a '%abc%' instead of 'abc%'.