I have a file which have data like
this is some data
this is other data
this is new data
Now I want to check(using a regex) whether a pattern exist in file or not. If yes then print the matched text and exit.
In case the pattern occurs more than once, then the one liner should break after first match.
Lets for example say that I want to check for pattern "data" in my file. I am using following one liner.
perl -ne'/(data)/ && print $1' file.txt
The problem with this is that it is
NOT exiting after first match and prints matched content thrice.
How can I modify this so that execution will stop after first match?
Please note that instead of "data" i can provide any regex. Also I can't use a script. This has to be a command line one liner in perl(no awk or grep). File size can be as big as 2 GB.