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
 Other Forums
 Other Topics
 Count the number of lines in a text file...

Author  Topic 

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-04-17 : 15:56:10
I need a way to know how many rows will be BCPed in from a file before the BCP is fired off . . .

I am thinking . . .

insert #cmdshell
exec @return = master..xp_cmdshell 'find /v /c "" <filename>'

select <string manipulation to parse out the count>
from #cmdshell
where @return = <valid return value>

 
where . . .
quote:

Find

Searches for a specific string of text in a file or files.
After searching the specified files, find displays any lines of text that contain the specified string.
find [/v] [/c] [/n] [/i] "string" [[drive:][path]filename[...]]

Parameters

"string"
Specifies the group of characters you want to search for. You must enclose the text for string in quotation marks.
[drive:][path] filename
Specifies the location and name of the file in which to search for the specified string.
/v
Displays all lines not containing the specified string.
/c
Displays only a count of the lines that contain the specified string.
/n
Precedes each line with the file's line number.

/i
Specifies that the search is not to be case-sensitive.



... so 'gimme the count of line in the file that do not contain nothing'. Does that sound legit?

<O>

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-04-17 : 17:26:05
I would maybe count the chr(13)'s. If your file doesn't have one empty row at teh bottom, you'll get 0 back.

Go to Top of Page
   

- Advertisement -