Adding line count number to find results

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Adding line count number to find results

#1 Post by ED209 » 30 Jan 2012 10:53

Hi,

I'm wondering if there's a way to add the the line number to the beginning of the below find command.. I don't mean using the /N action as it gives the line number placement in the file.. I'm looking for the count result number.. for example if there were 50 results, it would output the number 1 - 50 at the beginning of each find result

Code: Select all

find "Company" "%INPUT_DIR%\%INPUT_FILE%" >> %OUTPUT_DIR%\%OUTPUT_FILE%


Thanks,
Jaz

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Adding line count number to find results

#2 Post by Squashman » 30 Jan 2012 11:08

Pipe it to another find command before redirecting to your output file.

find "Company" "%INPUT_DIR%\%INPUT_FILE%" | find /v /n "" >> %OUTPUT_DIR%\%OUTPUT_FILE%

ED209
Posts: 8
Joined: 07 Jul 2011 12:17

Re: Adding line count number to find results

#3 Post by ED209 » 31 Jan 2012 03:06

Thanks for the reply... Had to change the first find to a findstr as it was counting the file location with the find command output as a line.. But it works..


Code: Select all

findstr "Company" "%INPUT_DIR%\%INPUT_FILE%" | find /v /n "" >> %OUTPUT_DIR%\%OUTPUT_FILE%



Thanks again..
Jaz

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Adding line count number to find results

#4 Post by dbenham » 31 Jan 2012 10:26

ED209 wrote:Had to change the first find to a findstr as it was counting the file location with the find command output as a line.. But it works..

Passing the file content to FIND with redirection instead of using file name as an argument eliminates the leading file location line problem.

Code: Select all

find "Company" <"%INPUT_DIR%\%INPUT_FILE%" | find /v /n "" >> %OUTPUT_DIR%\%OUTPUT_FILE%


Dave Benham

Post Reply