3 ms·
Sure: Ruby IO.foreach('logs1.txt') {|x| puts x if /\b\w{15}\b/.match? x } Python3 import re with open('logs1.txt', 'rt') as fh: for line in fh
by cutler 10y ago
Sure:
Ruby
IO.foreach('logs1.txt') {|x| puts x if /\b\w{15}\b/.match? x }
Python3
import re
with open('logs1.txt', 'rt') as fh:
for line in fh:
if re.search(r'\b\w{15}\b', line): print(line, end=' ')
Perl
open my $fh, '<', 'logs1.txt';
while (<$fh>) { chomp; say if $_ =~ /\b\w{15}\b/; }
close $fh;
NodeJS
var fs = require('fs'), byline = require('byline');
var stream = byline(fs.createReadStream('logs1.txt', {encoding: 'utf8'}));
stream.on('data', function(line) { if (line.match(/\b\w{15}\b/)) console.log(line); });
PHP
$fh = fopen('logs1.txt', 'r');
while (($line = fgets($fh)) !== false) {
if (preg_match('/\b\w{15}\b/', $line)) echo $line;
}
fclose($fh);