Tim Wolak am Freitag, 3. November 2006 18:37: > All, > > I need to parse lines from a file and at a certain position test to see > if it is what a want, if so I need to grab information from other > positions in the line and drop it into a file. As I have never done > this before, can someone point me in the right direction as to get > started? > > Thanks for the help! > Tim
Hello Tim I've read your second post with some sample data. Here's one way to do it, certainly not the most efficient, but it's short and you can adapt it to your needs. I use shorter sample data and other positions, but you get the idea. I use, for shortness, the DATA filehandle. You may want to adapt it to use STDIN for input and print to STDOUT, so you can invoke the script with $ script.pl < infile > outfile What it does: It skips 4 positions, tries to match 'hi' or 'ho' at the next 2, then skips 3, retrieves the next 2, skips again 8, and retrieves the next 6. The retrieve is done via capturing paranthesis, see perldoc perlre. Hope this helps, Dani #!/usr/bin/perl use strict; use warnings; while (<DATA>) { if (my (@out_fields)= $_ =~ /^ .{4} (hi|ho) .{3} (.{2}) .{8} (.{6}) /x) { print @out_fields, "\n"; } } __DATA__ 4444hi3332288888888first*---- 4444ho3332288888888second---- 4444no3332288888888third*---- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>