SED - Multiple String - Single Line

Would appear to me to be a farily simple question but having search all the threads I can't find the answer .. I just want sed to output the single line in a file that contains two string anywhere on the line..

e.g. currently using this command

sed -n -e'/str1/p' -e '/str2/p' < file

and get ..

str1 xxxxxxxxxxxxxxxxxxxxxxxx
str1 xxxxxxxxxxxstr2xxxxxxxxx
str1 xxxxxxxxxxxstr2xxxxxxxxx
str1 xxxxxxxxxxxxxxxxxxxxxxxx
str1 xxxxxxxxxxxxxxxxxxxxxxxx

So I get the line I want ( italics ) duplicated ..

I've no doubt this is very obvious .. please enlighten me ..

 
awk ' /str1.*str2/ { print $0}' filename
1 Like

Spot on .. thanks mate ..

Depending on the intended result :

# cat tst
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxx str1 xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx str2 xxxxx
str1 xxxxxxxxxxxstr2xxxxxxxxx
xxxx str1 xxxxxxxxxx str2 xxx
str1 xxxxxxxxxxxxxxxxxxx str2
xxxxxxx str1 xxxxxxxxxxx str2
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# sed '/str1.*str2/!d' tst
str1 xxxxxxxxxxxstr2xxxxxxxxx
xxxx str1 xxxxxxxxxx str2 xxx
str1 xxxxxxxxxxxxxxxxxxx str2
xxxxxxx str1 xxxxxxxxxxx str2
# awk '/str1.*str2/' tst
str1 xxxxxxxxxxxstr2xxxxxxxxx
xxxx str1 xxxxxxxxxx str2 xxx
str1 xxxxxxxxxxxxxxxxxxx str2
xxxxxxx str1 xxxxxxxxxxx str2
# awk '/^str1.*str2/' tst
str1 xxxxxxxxxxxstr2xxxxxxxxx
str1 xxxxxxxxxxxxxxxxxxx str2
#  sed '/^str1.*str2/!d' tst
str1 xxxxxxxxxxxstr2xxxxxxxxx
str1 xxxxxxxxxxxxxxxxxxx str2
#