- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- counting number of lines in file using dcl script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 12:37 AM
тАО11-13-2003 12:37 AM
Can anybody help me in writing a script to count number of lines for a ascii file? I do not want to use open /read loop thing.
If anybody can help me, I would be highly oblige.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 01:01 AM
тАО11-13-2003 01:01 AM
Re: counting number of lines in file using dcl script
$ search/statistics/nooutput sys$login:login.com ""
Files searched: 1 Buffered I/O count: 5
Records searched: 48 Direct I/O count: 2
Characters searched: 1162 Page faults: 26
Records matched: 48 Elapsed CPU time: 0 00:00:00.00
Lines printed: 0 Elapsed time: 0 00:00:00.02
but that doesn't store the result in a symbol -- is that something you need to do? If so, you probably do need to read in a loop, which isn't all that bad. Here's an example:
$ open/read a 'p1
$ count = 0
$ loop:
$ read/end=all_done a line
$ count = count + 1
$ goto loop
$ all_done:
$ close a
$ write sys$output "There are ",count," records in ", f$parse("''p1'")
$ exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 01:58 AM
тАО11-13-2003 01:58 AM
Solution1. Below is my text file:
DCCDT2> typ a.txt
this is test file
this is test file
this is test file
2. Here is my command procedure:
DCCDT2> type d.com
$set noon
$pipe sear/stat a.txt "" | sear sys$pipe lines > c.dat
$open/read x c.dat
$read x y
$d :== 'F$extract(14,19,y)
$sho sym d
$close x
$exit
3. And here I execute my command procedure . It give me no. of lines in file :
DCCDT2> @d
D == "3"
DCCDT2>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 02:19 AM
тАО11-13-2003 02:19 AM
Re: counting number of lines in file using dcl script
When you get that count, what are you going to do with it? If you use a tool like AWK or PERL then you can potentially immediatly use the number and add more value to it.
An other example of a tool telling you how many records there were:
$ app/log tmp.tmp nl:
%APPEND-S-APPENDED, U$1:[HEIN]TMP.TMP;4 appended to NL: (275 records)
Up to you to 'catch' that output and parse it.
A trivial perl example to set a logical name (NR) to the number of lines. It just does nothing reading the files and uses the perl built-in $. to report the count.
$ perl -E "while (<>){}; $ENV{""NR""}=$." < tmp.tmp
$ show log NR
"NR" = "275" (LNM$PROCESS_TABLE)
And an awk example:
$ gawk /comm="END {print NR}" tmp.tmp
275
What I could not figure out quickly enough, maybe a problem with the awk I have, is to return the numnber of lines encodeded in the exit status. Something like:
$ gawk /comm="END {exit 2*NR+1}" your-file
You could then maybe convert back to lines,
but it only returns 'abort' status (%X1000002C)
$ write sys$output "lines: ", ($STATUS - %X10000001)/2
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 08:18 AM
тАО11-13-2003 08:18 AM
Re: counting number of lines in file using dcl script
(beware wrapping...)
$ file="your-file-name"
$ PIPE SEARCH/STATISTICS/NOOUTPUT 'file' " " | -
SEARCH SYS$PIPE "records searched" | -
(READ SYS$PIPE line ; -
lines=F$ELEMENT(2," ",F$EDIT(line,"COMPRESS")) ; -
DEFINE/JOB lines &lines)
On completion, the JOB logical name "LINES" will contain the line count of your file. If the file doesn't exist, the count will be 0.
You'd be much better off writing a trivial program, 2 parameters, file name and symbol name:
$ countlines 'file' lines
$ WRITE SYS$OUTPUT "line count=''lines'"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2003 09:33 AM
тАО11-13-2003 09:33 AM
Re: counting number of lines in file using dcl script
and a little more as a one-liner also with pipes:
$pipe sea/log file xxx |( read sys$pipe l ; l=f$ele(3," ",l) ; defi/job l &l
)
Hein.