[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Text processing question

Posted on 2002-05-28
7
Medium Priority
?
174 Views
Last Modified: 2010-03-05
hello, the problemi is simple:

here's the input (.txt format):

##L
008L02C01---000225505
040L02C01---Agenti e rappresentanti
013L02C01---SEB Per 344.01
039L02C01---[SEB Per 344.01] ####2(2002)-
##L
008L02C01---000225469
040L02C01---Ambiente
013L02C01---SEB Per 344.046
039L02C01---[SEB Per 344.046] ####10(2002)-
##L
008L02C01---000186787
040L02C01---Ambiente & sicurezza
013L02C01---SEB Per 344.046
039L02C01---##2(2000)-  (SEB Per 344.046)
##L
008L02C01---000228903
040L02C01---Amministrazione civile
013L02C01---SEB Per 351
039L02C01---[SEB Per 351] ####2002-


and I'd like to obtain the following "polished" output:



Agenti e rappresentanti
SEB Per 344.01
2(2002)-


Ambiente
SEB Per 344.046
10(2002)-


Ambiente & sicurezza
SEB Per 344.046
2(2000)-  (SEB Per 344.046)


Amministrazione civile
SEB Per 351
2002-


is it possible?

thanks a lot,

Fabiano
0
Comment
Question by:fabianope
[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
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:dda
ID: 7038959
Very quick and dirty:
#!/usr/bin/perl -w

use strict;

while (my $s = <>) {
    chomp $s;
    if ($s =~ /##L/) {
        $s = <>;
        $s = <>;
     chomp $s;
        my @t = split /---/, $s;
        print $t[1], "\n";
        $s = <>;
     chomp $s;
        my @t = split /---/, $s;
        print $t[1], "\n";
        $s = <>;
        $s =~ /#+(.+)/;
        print $1, "\n\n";
    }
}
0
 
LVL 4

Expert Comment

by:dda
ID: 7038960
Run it as perl script.pl infile.txt > outfile.txt
0
 

Author Comment

by:fabianope
ID: 7041134
hello,
thanks for the quick answer

with windows NT + active perl Build 515 Friday, April 9, 1999 I obtainde the followingf error from the DOS shell:


C:\prl>vedi.pl kris.txt > kris2.txt
"my" variable @t masks earlier declaration in same scope at C:\prl\vedi.pl line
15.
Use of uninitialized value at C:\prl\vedi.pl line 19, <> chunk 235.

If you can delete these errors, all goes OK

bye

fabianope
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:fabianope
ID: 7041152
hello

another thing:

if I call the script as follows (in the worng manner..)


C:\prl>vedi.pl kris.txt

without output file, I obtain the right result on the STDOUT (the msdos shell)

hope it helps

bye

fabianope
0
 
LVL 4

Accepted Solution

by:
dda earned 800 total points
ID: 7041183
Please try to run as follows:

C:\prl>perl vedi.pl kris.txt > kris2.txt

I noticed that redirection may work incorrectly with winNT, and it is ok with w2k.
0
 

Author Comment

by:fabianope
ID: 7042104
Hello,
this time the result is correct but I obtain a strange error message:

"my" variable @t masks earlier declaration in same scope at ved
Use of uninitialized value at vedi.pl line 19, <> chunk 235.

can you resolve this?
everyway thanks: I've accepted the answer.

bye

Fabianope
0
 
LVL 4

Expert Comment

by:dda
ID: 7042404
Yes, it's my fault. Please just remove second 'my' from tge script:

#!/usr/bin/perl -w

                   use strict;

                   while (my $s = <>) {
                      chomp $s;
                      if ($s =~ /##L/) {
                          $s = <>;
                          $s = <>;
                       chomp $s;
                          my @t = split /---/, $s;
                          print $t[1], "\n";
                          $s = <>;
                       chomp $s;
                          @t = split /---/, $s;
                          print $t[1], "\n";
                          $s = <>;
                          $s =~ /#+(.+)/;
                          print $1, "\n\n";
                      }
                   }

Regards,
Dmitry.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

649 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