Sponsored Content
Top Forums Shell Programming and Scripting Perl Regex matching multiple lines Post 302486122 by chakrapani on Friday 7th of January 2011 04:54:02 AM
Old 01-07-2011
@pravin27 On windows with perl 5 I get error:

Can't find string terminator "'" anywhere before EOF at -e line 1.

---------- Post updated at 04:54 AM ---------- Previous update was at 04:45 AM ----------

@ludwig
Thanks ... it works
I modified the code a little bit
Code:
$\ = "\n";
$, = ': ';
open ( FILE, "input.txt") || die "Unable to open bill_data.txt";
while (<FILE>) {
    chomp;
    if (my ($d, $m, $y, $w, $f) = m{^X.*?(\d+)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\.\d+)$}) {
        my $amount = $w + $f;
        $_ = <FILE>;
        my ($account) = m{^to account (\d+)};
        print "\n   date", "$d-$m-$y";
        print 'account', $account;
        print ' amount', $amount;
    }
}
close(FILE);

But when I add to my original code .. .I does not work ... my original code below

Code:
#!/bin/perl
$| = 1;
$\ = "\n";
$, = ': ';
 
open ( FILE, "input.txt") || die "Unable to open txt file";
while(<FILE>) { 
chomp; 
if (/START OF STUFF/../End of Stuff/) 
{ 
# print "Line:$. $_\n";
chomp;
if (my ($d, $m, $y, $w, $f) = m{^X.*?(\d+)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\.\d+)$}) {
my $amount = $w + $f;
$_ = <FILE>;
my ($account) = m{^to account (\d+)};
print "\n date", "$d-$m-$y";
print 'account', $account;
print ' amount', $amount;
}
}
}
close (FILE);

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find -regex: matching multiple extensions

I want to use find to locate files with two different extensions, and run a grep on the results. The closest I have gotten is incredibly slow and ugly: for i in `ls -laR|egrep -e '(.js|.css)'`; do find . -name $i -print|xargs grep -H searchBg; done; This method makes my eyes bleed. Help! ;) ... (2 Replies)
Discussion started by: r0sc0
2 Replies

2. Shell Programming and Scripting

regex to delete multiple blank lines in a file?

can't figure out a way to delete multiple empty lines but keep single empty lines in a file, file is like this #cat file 1 2 3 4 5 6 - What I want is 1 2 (6 Replies)
Discussion started by: fedora
6 Replies

3. Shell Programming and Scripting

Perl regex help - matching parentheses

Let's say I'm trying to match potentially multiple sets of parentheses. Is there a way in a regular expression to force a match of closing parentheses specifically in the number of the opening parentheses? For example, if the string is "((foo bar))", I want to be able to say "match any number of... (7 Replies)
Discussion started by: cvp
7 Replies

4. Shell Programming and Scripting

pattern matching over multiple lines and deleting the first

I've got a longish log file with content such as Uplink traffic: Downlink traffic: I want to parse the log file and remove any line that contains the string "Uplink traffic:" at the beginning of the line, but only if the line following it beginnings with the string "Downlink traffic:" (in... (7 Replies)
Discussion started by: Yorkie99
7 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

Perl: Regex, string matching

Hi, I've a logfile which i need to parse and get the logs depending upon the user input. here, i'm providing an option to enter the string which can be matched with the log entries. e.g. one of the logfile entry reads like this - $str = " mpgw(BLUESOAPFramework):... (6 Replies)
Discussion started by: butterfly20
6 Replies

7. Shell Programming and Scripting

Filter (by max length) only lines not matching regex

I have a large file of many pairs of sequences and their headers, which always begin with '>' I'm looking for help on how to retain only sequences (and their headers) below a certain length. So if min length was 10, output would be I can filter by length, but I'm not sure how to exclude... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

Perl script: matching multiple lines error

Dear Perl users, Could somebody help me how to fix my code so I can get my desired output. Here is the data: Pattern Gabriel halo1 halo2 end Pattern Andreas halo1 halo2 endI want to grep multiple lines between the pattern /Pattern Gabriel / and /end/. Then I will store the output into... (6 Replies)
Discussion started by: askari
6 Replies

9. Shell Programming and Scripting

Perl Matching multiple variables

I am trying to match mulitple (3) variables. I found the sub given below on the web which works well when all vars are defined. But there are situations where one or two will not be defined (at least one will always be defined.) Example of the variable content possibilities The sub found... (4 Replies)
Discussion started by: popeye
4 Replies

10. Shell Programming and Scripting

Grepping or awking multiple lines in a file - regex

data.txt: hellohellohello mellomello1mello tellotellotellotello bellobellowbellow vellow My attempts: egrep ".*mello1\n.*bellow" data.txt awk '/.*mello1.*\nbellow/' data.txt how can i search for patterns that are on different lines using simple egrep or awk? i only want the... (7 Replies)
Discussion started by: SkySmart
7 Replies
NICOVIDEO-DL(1) 					      General Commands Manual						   NICOVIDEO-DL(1)

NAME
nicovideo-dl -- download a video file from www.nicovideo.jp SYNOPSIS
nicovideo-dl [options] video_url DESCRIPTION
This manual page documents briefly the nicovideo-dl command. This manual page was written for the Debian distribution because the original program does not have a manual page. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -h --help print this help text and exit -u USERNAME --username=USERNAME account username (e-mail address) -p PASSWORD --password=PASSWORD account password -o FILE --output=FILE output video file name -q --quiet activates quiet mode -s --simulate do not download video -t --title use title in file name -l --literal use literal title in file name -n --netrc use .netrc authentication data -g --get-url print final video URL only -2 --title-too used with -g, print title too -c --get-comment download comment -x --raw-comment save comment in raw xml --comment-output=FILE output comment file name -v --version print program version and exit SEE ALSO
youtube-dl (1). AUTHOR
This manual page was written by paulliu grandpaul@gmail.com for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the same terms as the license of the original software. NICOVIDEO-DL(1)
All times are GMT -4. The time now is 01:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy