Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Extract data

By: flukas88 on Nov 6th, 2012  |  syntax: Perl  |  size: 1.86 KB  |  views: 92  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2. #
  3. # Extract code v0.1
  4. # Luca Francesca
  5. #
  6. use strict;
  7.  
  8. # For colored output
  9. my $green="\e[32m";
  10. my $red="\e[31m";
  11. my $yellow="\e[33m";
  12.  
  13. #Making sure of the parameters
  14. if ($ARGV[0] eq "") {
  15.     print "Usage: $0 <file>\n";
  16.     exit -1;
  17. }
  18.  
  19. # Read input file...
  20. open INF, "< $ARGV[0]" or die "Error in program: $!";
  21. my @lines = <INF>;
  22. close INF;
  23.  
  24. print "$yellow Loading data... \n\n";
  25. print "$yellow Begin report... \n \n";
  26.  
  27. # .. and work with it
  28. foreach(@lines) {
  29.     #chomp($_);
  30.     my $cmd = "$_";
  31.     $cmd =~
  32.     /
  33.     GSMC(SC|AS) # first, check the type
  34.     /x;
  35.     my $type = $1;
  36.     if ($type eq "SC") {
  37.         $cmd =~
  38.         /
  39.         GSMCSC
  40.         \@    # delimiter
  41.         GSM
  42.         \@
  43.         (\d+) # param
  44.         \@
  45.         (\d+) # opt
  46.         \@
  47.         (\d+) # data
  48.         \@
  49.         (\d+) # priority
  50.         /x;
  51.         my $param    = $1;
  52.         my $opt      = $2;
  53.         my $data     = $3;
  54.         my $priority = $4;
  55.         print "$green Record type GSMCSC\n";
  56.         printf "%-15s %s\n", 'Parameter', $param;
  57.         printf "%-15s %s\n", 'Opt', $opt;
  58.         printf "%-15s %s\n", 'Data', $data;
  59.         printf "%-15s %s\n", 'Priority', $priority;
  60.         print "## \n \n";
  61.     } elsif ($type eq "AS") {
  62.         $cmd =~
  63.         /
  64.         GSMCAS
  65.         \@    # delimiter
  66.         GSM
  67.         \@
  68.         (\d+) # service
  69.         \@
  70.         (\d+) # data
  71.         \@
  72.         (\d+) # priority
  73.         /x;
  74.         my $service  = $1;
  75.         my $data     = $2;
  76.         my $priority = $3;
  77.         print "$green Record type GSMCAS\n";
  78.         printf "%-15s %s\n", 'Service', $service;
  79.         printf "%-15s %s\n", 'Data', $data;
  80.         printf "%-15s %s\n", 'Priority', $priority;    
  81.         print "#-# \n \n";
  82.    
  83.     }
  84. }
  85.  
  86. print "$red Report done!\n";
  87. print ""
  88.  
  89. #@