cyber-33
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 "
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 "
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);
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solved
set FileName=%1%
set token1=%2%
set token2=%3%