How to get the last word in the last line in a file with Windows batch script? -


i have file sample.txt content below.

h|20170331|cis a||a1140|grm  //header a||a1140|grm a||a1140|grm a||a1140|grm a||a1140|grm t|20170331|5  //trailer 

i need last token in last line i.e. 5. (it's count of line except header trailer).

as of now, tried below; it's giving first token, i.e. t, need last token i.e. 5.

@echo off rem /f "skip=1 tokens=2,* delims=" %%a in (sample.txt) set "variable=%%a"  rem /f "delims=|" %%x in (sample.txt) set "variable=%%x" /f "delims=|" %%g in (sample.txt) set "variable=%%g" echo %variable%  pause 

note file can contain thousands of records last token required.

presuming want rid of //trailer add space delimiter.

@echo off /f "tokens=3delims=| " %%a in (sample.txt) set lastrowcol3=%%a echo [lastrowcol3=%lastrowcol3%] 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -