Operating System - OpenVMS
1748272 Members
4275 Online
108760 Solutions
New Discussion юеВ

Re: open a logoutput and filter it.

 
Taulant Shamo
Frequent Advisor

open a logoutput and filter it.

Hello All,

How can I open a oputput file and how can filter contents in way in the file attached described:
7 REPLIES 7
Bojan Nemec
Honored Contributor

Re: open a logoutput and filter it.

Hi,

You open the files with:

OPEN logical-name filename

When you open a file for writing you use the /WRITE or /APPEND qualifier (write for new file and append for appending to end of an existing file).
When you open a file for reading use the /READ qualifier.
So if yours attached file is a log file named logfile.log, you open it with:
OPEN/READ mylog logfile.log
Now you can read it with the READ command.

To filter the contents you must write a procedure like this:

$ OPEN/READ LOG logfile.log ! substitute the name with a full name to yours logfile
$ OPEN/WRITE FILT filtered.log ! same as previous line
$L1:
$ MSISDN=""
$ STATUS=""
$ ACC_TIME=""
$ SMS_TEXT=""
$L2:
$ READ LOG LINE/END=END
$ IF F$EXTRACT(0,13,LINE).EQS."Input MSISDN:"
$ THEN
$ MSISDN=F$ELEMENT (1,":",LINE)
$ GOTO L2
$ ENDIF
$!repeat the if for each line you are interested.
$!the last test is a litle different
$ IF F$EXTRACT(0,11,LINE).EQS."Accept time"
$ THEN
$ ACC_TIME=F$ELEMENT (1,":",LINE)
$ GOTO WRITE_OUT
$ ENDIF
$ GOTO L2 !Line is not interesting.
$WRITE_OUT:
$ WRITE FILT F$FAO("!20AS !10AS !14AS !AS",MSISDN,STATUS,ACC_TIME,SMS_TEXT)
$!play with the lengths to get the right output
$ GOTO L1
$END:
$ CLOSE LOG
$ CLOSE FILT


This is only one possible approach, there are many other posibilities.
When you write a procedure you will need lexical functions (F$something). Do a HELP LEXICAL for help on them. You can also look to the HP OpenVMS DCL Dictionary:
http://h71000.www7.hp.com/doc/732FINAL/9996/9996PRO.HTML

Bojan
John Gillings
Honored Contributor

Re: open a logoutput and filter it.

Taulant,
You can probably simplify the task by prefiltering the file with SEARCH. I'm not certain where all your output fields come from, but this may be a reasonable start:

$ SEARCH yourfile.log " at ","Input ", "result","Accept time"

Add additional keywords to include more lines from the input file. If you're running V7.2 or above, you can also PIPE
SEARCH commands together. For example:

$ PIPE SEARCH yourfile.log -
" at ","Input ", "result","Accept time" | -
SEARCH SYS$PIPE "%x" /MATCH=NOR

the first SEARCH will include matching lines in the output, the second will exclude some of those. It's all a matter of selecting the appropriate keywords to identify certain lines. For example, I've chosen " at " because it preceeds all your dates in output lines.

This may make your final processing simpler. You can even pipe the final stage of the SEARCH into your procedure.

A crucible of informative mistakes
Hein van den Heuvel
Honored Contributor

Re: open a logoutput and filter it.


I like perl for these kind of jobs.
Something along the lines of:

$format = "%-12s %-12s %-14s %-17s\n";
printf $format, "MSISDN:", "Status:", "Accepted Time:", "SMS Text:";
printf $format, "------------","------------","--------------","------------------";
while (<>) {
$MSISDN = $1 if (/Input MSISDN:\s(\w+)/);
$SMtext = $1 if (/Enter SM text :\s*(.*)$/);
$Status = $1 if (/Submit result\s+\w+\s*\w+\s+:\s+\d+,\s+(.*)$/);
if (/Accept time\s+:\s+(\d+)/) {
printf $format, $MSISDN, $Status, $1, $SMtext;
$MSISDN = $Status = $SMtext = "-";
}
}


See the structure?
- Set up some formating rules, and print header
- Loop through file
- Stash away specific matches (strings in paratheses)
- Print result on final match
- Clear other matches 'just in case'
- loop

Hein.


Taulant Shamo
Frequent Advisor

Re: open a logoutput and filter it.

Hi Bojac

I created the file as u write and and run the file @file.com a FILTER.LOG is created but nothing contain . the file to be filtered I called logfile.log as in your script. Please have a look.
Taulant Shamo
Frequent Advisor

Re: open a logoutput and filter it.

Helo Hein van den ,

I tried your sugestion about formating.
THe file can be filtered first and than I can format? also I dont see which file is formated or I'm wrong? SEE the printout reasul attached.
Bojan Nemec
Honored Contributor

Re: open a logoutput and filter it.

Hi,

The procedure in my previous post was just an example. I dont know why it is not working with jours log file. I can make only some suppositions.
First, the name of yours log file can be anything, but it must point right to the log file. So replace my logfile.log with a full file specification of yours log file.
Inspect the contents of yours logfile (with an editor or with type) and see what is the content of the lines you are interested. The Ifs must match the contents. So you must modify the f$extract and the contents of the string inclused in "". The f$extract lexical function, extracts a substring from a string (which is the third parameter) the first parameter is the starting position (0 is the first character) and the second parameter is the length of the substring. Please se more by typing help lexicals f$extract.

You can debug the procedure by typing
$ SET VERIFY
before running the command procedure. This will display each executed line. ($ SET NOVERIFY to stop displaying). Also you can add some show symbol to the command procedure.

And try Johns solution, maybe it will be more simple for you.

Bojan

Hein van den Heuvel
Honored Contributor

Re: open a logoutput and filter it.

Ah, you must be unfamiliar with perl.
I just used 'word' to save your first attachement as text.
Then I use that as input for the perl script I showed.
Results:

$ crea test.pl
$format = "%-12s %-12s %-14s %-17s\n";
printf $format, "MSISDN:", "Status:", "Accepted Time:", "SMS Text:";
printf $format, "------------","------------","--------------","----------------
--";
while (<>) {
$MSISDN = $1 if (/Input MSISDN:\s(\w+)/);
$SMtext = $1 if (/Enter SM text :\s*(.*)$/);
$Status = $1 if (/Submit result\s+\w+\s*\w+\s+:\s+\d+,\s+(.*)$/);
if (/Accept time\s+:\s+(\d+)/) {
printf $format, $MSISDN, $Status, $1, $SMtext;
$MSISDN = $Status = $SMtext = "-";
}
}

Exit
$ perl test.pl < test.txt
MSISDN: Status: Accepted Time: SMS Text:
------------ ------------ -------------- ------------------
355692223557 Success 04092715141856 Site #10 MTX is out of service. NMC
355692223557 Success 04092715231956 SITEOOS
355692223557 Success 04092715374556 TEST
355692223557 Success 04092715374956 TEST


Close to what you need?
Hein.