Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 count number of lines in a text file

Author  Topic 

nehj76
Starting Member

15 Posts

Posted - 2007-08-23 : 14:23:54
Hi there!

I need help on how to count the number of lines in a text file..
Pls. advise

thanks in advance

X002548
Not Just a Number

15586 Posts

Posted - 2007-08-23 : 14:28:11
with or with out page breaks?

In any case, if this is a sql server question, then bcp the file to a staging table

then SELECT COUNT(*) FROM Stage




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

nehj76
Starting Member

15 Posts

Posted - 2007-08-23 : 14:34:39
Hi Brett,

I need to open a text file and check if how many lines are there

for ex.. file c:\test\test.txt has 8 records..
in TSQL, how can i actually count the number of records that test.txt actually has?

thanks..



Go to Top of Page

nehj76
Starting Member

15 Posts

Posted - 2007-08-23 : 14:36:51

c:\test\test.txt is terminated with a line-feed character
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-08-23 : 14:37:18
No. Or not to the best of my (limited) knowledge

Load the file to a table and you can then count them

Best you can do is to know the size of the file in TSQL



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-08-23 : 15:18:41
http://www.fileviewer.com/

"V is an all-purpose File Manager for Windows (95/98/Me/XP/NT4/2000/2003).

Although V might look like another Windows Explorer replacement, its main strength is its file viewing capabilities. It excels at viewing files quickly - whether the files are 100 bytes or 100 gigabytes. Support for EBCDIC files (including common RECFM formats) make it ideal for those who work in a mainframe environment. "



CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 15:41:46
Or open the file with OPENROWSET as

SELECT COUNT(*) FROM OPENROWSET(....)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

nehj76
Starting Member

15 Posts

Posted - 2007-08-23 : 15:42:10
Hi Guys,

I was able to find the solution:


declare @testing varchar(255)

drop table [dbo].[testfile]
CREATE TABLE [dbo].[testfile] (
line varchar(255) null
);

insert into [dbo].[testfile] EXEC master..xp_cmdshell 'find /c " " M:\ACE\Dataout\daily\si082307.txt'
set @testing = (select top 1 right(line,2) from [dbo].[testfile] order by line desc)

print @testing


Thanks
Go to Top of Page
   

- Advertisement -