Solved

A script to parse text documents

Posted on 2010-09-02
5
655 Views
Last Modified: 2013-12-14
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 "


0
Comment
Question by:cyber-33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:oleggold
ID: 33590629
my.cmd  FileName token1 token2:
set  FileName=%1%
set token1=%2%
set  token2=%3%
0
 

Author Comment

by:cyber-33
ID: 33591529
Not sure how to interpret your answer...
0
 
LVL 10

Expert Comment

by:jeromee
ID: 33591864
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);
0
 
LVL 10

Accepted Solution

by:
jeromee earned 500 total points
ID: 33591897
Fixing a small typo to make it work for multiple lines...
use strict;

my($filename, $tk1, $tk2) = @ARGV;
open(FILE, $filename) || die "Can't open $filename: $!\n";
$_ = join("", <FILE>);
my($found) = /$tk1(.*)$tk2/s;
print length($found)." $found" if $found;
close(FILE);

Open in new window

0
 

Author Closing Comment

by:cyber-33
ID: 33704140
Solved
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question