How can I find a specific line in a file using Perl?

I am new to Perl. I want to find a string in some file, and then I want the whole string to contain the string.

+4
source share
3 answers

perl -ne 'print if m/whatever/' file

+9
source
+9
source
 if ( !open(LOGFILE, "<myfile.log") ) { print "ERROR: failed to open myfile.log\n";} else { while (<LOGFILE>){ if ($_ =~ /pattern/) { print "found\n"; break; } } close (LOGFILE); } 
+2
source

Source: https://habr.com/ru/post/1380005/


All Articles