in reply to how to isolate text in a text file.
Hi, welcome to Perl, the One True Religion. Please start with perlintro. It'll take you less than an hour and afterwards you'll be able to understand the concepts demonstrated below.
Yes, this is possible using a Regular Expression to perform a Pattern Match.
Copy this into a file and run it with $ perl <filename>:
use strict; use warnings; use feature 'say'; my $txt = q{ Uninteresting line. More boring stuff. Here's the AATCCGCTAG string. Afterwards, more drivel. Footnotes, etc. }; my @lines = split "\n", $txt; my $counter = 0; for my $line ( @lines ) { $counter++; next unless $line =~ /(\b[ACGT]+\b)/; say "Found $1 in line $counter"; } __END__
See perlrequick for the beginner's regular expression tutorial.
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to isolate text in a text file.
by Aldebaran (Curate) on Dec 15, 2018 at 00:24 UTC |