multiple search keyword in grep

Dear All,
I have a file containing info like
TID:0903 asdfasldjflsdjf
TID:0945 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh
TID:1945 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh

I need to show only lines containing

TID:0903 asdfasldjflsdjf
TID:0945 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh

but I put the command

grep 'TID:09\|TID:20' filename.txt

but shows nothing.
Can any one help?

hi

i guess u are trying to find a string of words?

try to use "TID:09*" instead of ' '

hope this helps.

Hi Saif,

Try this.
egrep "TID:09|TID:20" Filename.txt

Cheers,
gehlnar

Thanks to all of you :b:
egrep worked !!!

Just for info,,,

this also can be used...

sed -n '/TID:09\|TID:20/p' inputfile.txt

output:
$ sed -n '/TID:09\|TID:20/p' inputfile.txt
TID:0903 asdfasldjflsdjf
TID:0945 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh
TID:2045 hjhjhkhkhkh

Thanks
Sha

Thanks to all of you. Just of being curious
is it possible to grep with multiple condition (like and operation) like

A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78
A:T00 B:88 C:78 D:60
A:T00 B:88 C:78

grep --------- filename

A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78 D:60

But I don't want to use PIPE. Using pipe it is alrite. But without pipe is it possible?

egrep '^TID:(09|20)'  a.txt

Hi Summer, actually you are rite. But what I am seeking for is the previous example.if A: and D: both are found in a line it needs to be shown.

This one may help your need

awk '{if(/A/) {if(/D/) print $0 }}' inputfilename

Thanks
Sha

file contains
A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78
A:T00 B:88 C:78 D:60
A:T00 B:88 C:78

bash-2.05$ awk '{if(/A/) {if(/D/) print $0 }}' multigrep.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

no need explicit "if"s

awk '/A/ && /D/' file

Hi,

In my System its working good.. :slight_smile:
see my output:
$ cat out.lst
A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78
A:T00 B:88 C:78 D:60
A:T00 B:88 C:78

$ awk '{if(/A/) {if(/D/) print $0 }}' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60

Or you can use below one as well..

$ sed -n '/A.*D/p' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60
$ sed '/A.*D/!d' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60
$ sed '/A/!d; /D/!d' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60

Thanks
Sha