2

I am using TrailerCount.bat file to count the number of lines in text file using below mentioned code

@Echo off
::set newline=^& echo.

SET FilePath=%1

Set /a _Lines=0

For /f %%j in ('Type %FilePath%^|Find "" /v /c ') Do Set /a _Lines=%%j

(
echo TRAILER %_Lines% 
)>>%FilePath%

Here when I am passing the txt file as a first input to batch file. After running it, its giving me Trailer as 8 in the last line of Text File which is correct if we open text file with "NOTEPAD". But using "Notepad++" it should be 11.

What changes i need to make to count empty lines,etc to get correct trailer count with respect to Notepad++???

3

The batch file is working correctly. find won't count a line unless it has the Windows LFCR* symbols on the line. You need to change the text file to have the LFCR symbols at the end of each line.

*LFCR is Line Feed, Carriage Return.

1
  • @abhayk, if the file doesn't have the line feed (LF) and carriage return (CR) characters used by Microsoft Windows, because it was produced on a computer using another operating system, such as Linux, OS X, etc., you can convert from the newline representation on another OS using techniques mentioned at Windows command to convert unix eol to windows eol – moonpoint Jul 31 '15 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.