Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Tasks to count lines in a text file
Topic Summary:
Created On: 04/15/2005 02:30 PM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 04/15/2005 02:30 PM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

These tasks count lines in a text file. This first one will handle UNIX and Windows files.

The three different versions (see my other posts) should all correctly handle an empty file (zero lines) or a file whose last line doesn't contain an LF.


Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI

Edited: 05/06/2006 at 10:05 AM by Pete
 04/15/2005 02:50 PM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

This version is a lot faster, but it doesn't work with UNIX files.


Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI
 04/15/2005 03:28 PM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

Also, if the file contains fixed-length records (i.e. every line is the same length), then this is the fastest version of all of them.


Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI
 04/15/2005 03:36 PM
User is offline View Users Profile Print this message

Author Icon
NoNo
n00b (>6 posts)

Posts: 4
Joined: 03/30/2005

Hey thanks a mill, Pete. Mucho Appreciated!
 04/15/2005 03:37 PM
User is offline View Users Profile Print this message

Author Icon
JohnDavis
Journeyman (50-99)

Posts: 63
Joined: 03/31/2005

Awesome!!! Thank You@!@!!!
 04/16/2005 08:05 PM
User is offline View Users Profile Print this message

Author Icon
StevePlotnick
Apprentice (20-49)

Posts: 24
Joined: 03/30/2005

I acquire the record count in one statement so that I can show a record counter every 100 records within a script. Here the second statement gets the total number of records.


Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)
 08/08/2006 03:55 AM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

This C++ program will allow you to investigate the line terminators when you're having problems with a particular text file.

It will display output such as the following:

Null character(s) found on line 1
Lines with only a CR: 0
Lines with only a LF: 0
Lines with CRLF: 2

(It checks for nulls because BASIC's 'Line Input' command will not find the line terminators on lines which contain nulls. Nulls produce incorrect results only when you use the second posted task in this forum topic.)

You can compile the .cpp program yourself or simply run the .exe file. You'll want to run it in a DOS box (c m d.exe) and specify a filename (e.g. CheckLineTerminators.exe "C:\My Data File.txt").




-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI

Edited: 08/08/2006 at 11:24 AM by Pete
 08/08/2006 04:20 AM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

To add to the collection, here's a C++ version that counts lines in a text file. It will put the number of lines in the return code, or -1 if there was an error. You can obtain the return code in a Run action in Automate or whatever.

This version will work with either UNIX or Windows text files. It will undoubtedly be the fastest version of all of them.

CountLines.zip
CountLines.zip  (29 KB)



-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI

Edited: 08/08/2006 at 11:25 AM by Pete
 08/08/2006 11:29 AM
User is offline View Users Profile Print this message

Author Icon
Pete
Master (500-999)

Posts: 740
Joined: 03/30/2005

I didn't think of using a zip file this morning, but I just successfully posted the source code and the .exe files inside zip files in my previous two posts.

-------------------------
AutoMate Pro 7.1.1.0 (Medium isolation level)
WinXP Home sp3, "Classic Theme", 120 DPI
 07/20/2007 12:40 PM
User is offline View Users Profile Print this message

Author Icon
Kelly Morris
Apprentice (20-49)

Posts: 31
Joined: 05/02/2007

Steve,

Are you able to get this to work if the file contains no rows? I can't get this to work in my task when my files are empty - it errors out and won't create the dataset for me to use to list the file count.
 10/17/2013 09:13 AM
User is offline View Users Profile Print this message

Author Icon
Poshiden
Apprentice (20-49)

Posts: 38
Joined: 01/08/2013

This was very helpful

 

thanks Pete!

Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1460 guests browsing this forum, which makes a total of 1460 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog