Operating System - OpenVMS
1748169 Members
4249 Online
108758 Solutions
New Discussion юеВ

reading specific line no.

 
SOLVED
Go to solution
nipun_2
Regular Advisor

reading specific line no.

Hi,
I have been posting too many queries lately as I am in crunch time!!!.
Thanks a bunch for helping out.

Even though I have not responded to few of them I have read and applied them and it has worked wonders!!!

I am trying to read specific line nos from a personal log file and make a new "results.txt" file.

However, I am not able to do so and I am not able to figure out the reason.

IPLXXX - perosonal log file
LINE_NO.TXT - Contains the line nos(one in each line e.g
23
34
.
.
.
45
[end]
I wish to read from personal log file )
Results.txt - Should contain the specified lines copied from IPLXXX.log


Here is the script
$ open read_con IPL_ALL_RESULTS_TRAB.LOG
$ open read_line LINE_NO.TXT
$ open/write output []results.txt
$ count =0;
$ LOOP1:
$ read /end_of_file=END read_con linex
$ count = count+1
$! read /end_of_file=END read_line line
$ if count .eq. line then write output linex
$ GOTO LOOP1
$ END:
$ close read_con
$ close output
$ close read_line
$ exit


8 REPLIES 8
Antoniov.
Honored Contributor
Solution

Re: reading specific line no.

Here is the new script
$ open read_con IPL_ALL_RESULTS_TRAB.LOG
$ open read_line LINE_NO.TXT
$ open/write output []results.txt
$ count =0;
$ LOOP1:
$ read /end_of_file=END read_con linex
$ count = count+1
$! read /end_of_file=END read_line line
$! =====================================
$! I suppose line is read from file
$! so it's string variable
$! In your example is not defined
$! =====================================
$ if count .eq. f$int(line) -
then write output linex
$ GOTO LOOP1
$ END:
$ close read_con
$ close output
$ close read_line
$ exit

Antonio Vigliotti
Antonio Maria Vigliotti
David B Sneddon
Honored Contributor

Re: reading specific line no.

Try the following...

$ set noon
$ closee/nolog numbers
$ closee/nolog textfile
$ closee/nolog results
$ openn/read/error=bail_out numbers line_no.txt
$ openn/read/error=bail_out textfile ipl_all_results_trab.log
$ copyy/nolog NLA0: results.txt
$ openn/append/error=bail_out results results.txt
$ tcount = 0
$nloop:
$ readd/end_of_file=end_nloop/error=end_nloop numbers counter
$tloop:
$ readd/end_of_file=end_tloop/error=end_tloop textfile textline
$ tcount = tcount + 1
$ if (tcount .ne. counter) then goto tloop
$ if (tcount .eq. counter) then writee/error=bail_out results textline
$end_tloop:
$ goto nloop
$end_nloop:
$ closee/nolog results
$ closee/nolog textfile
$ closee/nolog numbers
$ exitt 1


Dave
David B Sneddon
Honored Contributor

Re: reading specific line no.

Of course the line

$bail_out:

should appear just before the $ exitt 1

Dave
Hein van den Heuvel
Honored Contributor

Re: reading specific line no.


I'd use perl for this:

$ cre t.tmp
aap
noot
mies
teun
vuur
$ cre l.tmp
3
5
$ perl -e "open L,shift @ARGV;while (){chop;$l{$_}=1} while (<>) {print if $l{$.}}" l.tmp < t.tmp > r.tmp
$ type r.tmp
mies
vuur
$

This first reads the line number file and set an associative array element to 1 for each number found.
Next it loops through the rest of the input and prints if the array element for the current line number ($.) is true.
Done.
The line numbers need not be sorted.

If they are sorted and you must use DCL then check this out:

$ closee/nolog numbers
$ closee/nolog textfile
$ closee/nolog results
$ create r.tmp
$ open numbers l.tmp
$ open textfile t.tmp
$ open/append results r.tmp
$ tcount = 0
$
$number_loop:
$ readd/end=done numbers counter
$loop:
$ readd/end=done textfile textline
$ tcount = tcount + 1
$ if (tcount .lt. counter) then goto loop
$ write results textline
$ goto number_loop
$
$done:
$ closee/nolog results
$ closee/nolog textfile
$ closee/nolog numbers
$ exitt 1


hth,
Hein.
Hein van den Heuvel
Honored Contributor

Re: reading specific line no.


btw... not exactly what you want, but it 'looks' close and is cute (in my sick mind):

$ editt/edt/com=l.tmp t.tmp
3 mies
5 vuur
5 vuur
*

sorry, couldn't resist.

Hein.
nipun_2
Regular Advisor

Re: reading specific line no.

Thanks for the reply. Basically doing what Antoniov mentioned did the trick. However, now I have a different problem with the script. But I will post it as a new thread

John Gillings
Honored Contributor

Re: reading specific line no.

With V8.2 or higher, you can use the SEARCH command to select a specific line from a file. For example:

$ SEARCH file ""/SKIP=22/LIMIT=1

will display line 23

A fairly expensive method to do what you want is therefore:

$ OPEN/WRITE log IPLXXX.LOG

then use

$ SEARCH file ""/SKIP=line-1/LIMIT=1/OUT=log

Probably not a really practical way to do what you want, but worth pointing out some of the less obvious uses for the new features of SEARCH
A crucible of informative mistakes
nipun_2
Regular Advisor

Re: reading specific line no.

Thank you for your reply John,
I will keep the use of search in mind. I believe search normally does work in V7.3-2 (the way you have shown) unless there is something specifically different in V8.2 (from earlier versions of search )that you are trying to show here.