Link to home
Start Free TrialLog in
Avatar of cyber-33
cyber-33Flag for United States of America

asked on

A script to parse text documents

I am looking for a simple script that would take 3 parameters;
1. FileName
2. token1
3. token2

The script would search FileName and output a number of characters between token1 and token2 if both tokens exist. Ideally, it would also output the string appearing between token1 and token2.

Example:
Given a file1 that looks like this "123 321 234 543".
given the name of script: process1.

A dos command like: "process1 file1 321 543" would output 5 and " 234 "


Avatar of oleggold
oleggold
Flag of United States of America image

my.cmd  FileName token1 token2:
set  FileName=%1%
set token1=%2%
set  token2=%3%
Avatar of cyber-33

ASKER

Not sure how to interpret your answer...
Try this:

use strict;

my($filename, $tk1, $tk2) = @ARGV;
open(FILE, $filename) || die "Can't open $filename: $!\n";
$_ = join("", <FILE>);
my($found) = /$tk1(.*)$tk2/m;
print length($found)." $found" if $found;
close(FILE);
ASKER CERTIFIED SOLUTION
Avatar of jeromee
jeromee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Solved