If characters within a line, you need not only to actually read the file (as Corion mentioned); you need to process the current line... and incrementing $count won't do that for you.
Update: adding code (and subsequently, removing some debug matter)
#!/usr/bin/perl use strict; use warnings; # 848449 =head OP says: Question is u have a file A ACEEWSMKIIWSDJDWKDKEKSSAQWE and want to extract lines with option 5-10 with output like SMKII ## ww reads this as: I have a file with lines like ACEEWSMKIIWSDJDWKDKEKSSAQWE 012345678901234567890123456789 0 1 2 and want to extract characters at positions, 5 .. 9, where the character position is 0-based. =cut if ( $#ARGV < 2 ) { print "Usage: extract.pl firstLine lastLine filename\n"; exit 1; } my $start = $ARGV[0]; my $stop = $ARGV[1]; my $file = $ARGV[2]; my ($line_elements, @line_elements); open (FILE, '<', $file) or die "Can't open file $file $!"; while (<FILE>) { my $line = $_; my @line_elements = split (//,$line); my (@wanted, $wanted); for ($start .. ($stop-1) ) { push @wanted, $_; } for $wanted(@wanted) { for ($line_elements[$wanted]) { print "$line_elements[$wanted]"; } } print "\n\tNext line in file: \n"; }
where content of the input file, 848449.3line.txt, exceeds OP's original requirement, and is:
ACEEWSMKIIWSDJDWKDKEKSSAQWE abcdefghijklxxxxmnop 12345---678xxxx
where CLI and output is
hth.>perl 848449.pl 5 10 848449.3line.txt SMKII Next line in file: fghij Next line in file: ---67 Next line in file: >
In reply to Re: print and extract the line
by ww
in thread print and extract the line
by vis1982
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |