UNIX: Using egrep or sed to find the line with the first occurrence of a string? UNIX: Using egrep or sed to find the line with the first occurrence of a string? unix unix

UNIX: Using egrep or sed to find the line with the first occurrence of a string?


Use this:

grep -m1 auir myfile.txt


This sed command

sed -n '/auir/p' myfile.txt | head -1

solves your problem.


This might work for you:

sed '/auir/!d;q' file

or

sed -n '/auir/{p;q}' file