Solved

A script to parse text documents

Posted on 2010-09-02
5
654 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

734 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