Solved

A script to parse text documents

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now