I need to help to work this
Print everything between 2 patterns if grep is not found the search word
example
Detroit
orange
cat
bat
rat
apple
sed -n "/Detroit,/apple/p" d |grep chicago
output would be
Detroit
orange
cat
bat
rat
apple
I need to help to work this
Print everything between 2 patterns if grep is not found the search word
example
Detroit
orange
cat
bat
rat
apple
sed -n "/Detroit,/apple/p" d |grep chicago
output would be
Detroit
orange
cat
bat
rat
apple
Not sure if I understood this, but what do you want to display if grep **does** find something in the file?
I assume in that case you want to show the output of grep.
Is the following what you're looking for?
$
$ cat f34
Detroit
orange
cat
bat
rat
apple
$
$
$ # grep doesn't find anything in the file; show the output of sed
$
$ grep chicago f34 || sed -n '/Detroit/,/apple/p' f34
Detroit
orange
cat
bat
rat
apple
$
$
$ # grep does find something in the file; show the output of grep, do not show the output of sed
$
$ grep cat f34 || sed -n '/Detroit/,/apple/p' f34
cat
$
$