I was struggling the last days for converting my applications from UNIX servers to Windows servers. The main difficulty I faced was the conversion of the shell scripts to DOS Batch scripts. Since I was not that expert in UNIX Shell commands, it was a challenge for me. I will keep on posting the different conversions I did. This is the first one.
The tail command in UNIX will take the last specified number of lines from the input given. The below line of command will take last 20 lines from del_temp.log and put into value.log.
tail -20 del_temp.log >> value.log
This single line tail command can be converted to its equivalent DOS Batch by the below block of code.
SETlocal EnableExtensions
SET tailCount=20
SET fileName=del_temp.log
SET output=value.log
FOR /F “usebackq tokens=3,3 delims= ” %%l IN (`find /c /v “” %fileName%`) DO (call SET find_lc=%%l)
SET /a linenumber = %find_lc% – %tailCount%
IF %linenumber% LSS 1 (
more +0 %fileName% >> %output%
) ELSE (
more +%linenumber% %fileName% >> %output%
)
endLocal
Enjoy and Happy Coding Guys 🙂