Page 1 of 1

Adding line count number to find results

Posted: 30 Jan 2012 10:53
by ED209
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

Re: Adding line count number to find results

Posted: 30 Jan 2012 11:08
by Squashman
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%

Re: Adding line count number to find results

Posted: 31 Jan 2012 03:06
by ED209
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

Re: Adding line count number to find results

Posted: 31 Jan 2012 10:26
by dbenham
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