Computing.Net > Forums > Programming > Get linecounts from multiple files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Get linecounts from multiple files

Reply to Message Icon

Name: hgediya
Date: July 10, 2009 at 09:11:06 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

hey experts,

I want to know if is there any way can I get the batch file code which count the number of records from multiple files from particular location and give me output in excel with column says filename, no of records

Appreciate your help



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 10, 2009 at 12:57:57 Pacific
Reply:

If the files are text files, that is possible, stated the result is a .csv file you can then import into excel.

The following script is an example

:: FILECNT.BAT Usage: filecnt Folder_Name
@echo off > output.csv
pushd %*
for %%j in (*.txt) do (
  for /F  %%k in ('type "%%j" ^| find /V /C ""') do echo.%%j,%%k>> output.csv
)
popd
:: End_Of_Batch


0

Response Number 2
Name: hgediya
Date: July 23, 2009 at 11:50:06 Pacific
Reply:

hey thanx a lot IVO,
As I seen couple of post from u here, I Was expectig u to answer.....

I Appreciate your help.


0

Response Number 3
Name: ghostdog
Date: July 23, 2009 at 19:20:00 Pacific
Reply:

you can eliminate the outer for loop. more efficient this way.

...
for /F "tokens=2*"  %%l in ('find /V /C "" *.txt') do echo %%l%%m
.....

GNU win32 packages | Gawk


0

Response Number 4
Name: hgediya
Date: July 29, 2009 at 07:41:36 Pacific
Reply:

thanx a lot ghostdog

your solution works more efficient ,
Although first solution also does work, but sometimes it says unable to read file at first time and when I run it again it able to read files.So I was bit confused and then I tried second solution posted by you, it works better as I expected.

I appreciate for your help guys............
Thanx again


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Get linecounts from multiple files

Get first line from a file www.computing.net/answers/programming/get-first-line-from-a-file/14984.html

Copy from multiple directories www.computing.net/answers/programming/copy-from-multiple-directories/16232.html

Extracting rows from multiple csv files using www.computing.net/answers/programming/extracting-rows-from-multiple-csv-files-using/20204.html