Solved

A script to parse text documents

Posted on 2010-09-02
5
640 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
Comment Utility
my.cmd  FileName token1 token2:
set  FileName=%1%
set token1=%2%
set  token2=%3%
0
 

Author Comment

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

Expert Comment

by:jeromee
Comment Utility
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
Comment Utility
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
Comment Utility
Solved
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

6 Experts available now in Live!

Get 1:1 Help Now