Mostly Linux & Python syntax notes and hyperlinks.

Wednesday, July 8, 2020

Windows batch script - decimal points and comma separators

Adding a decimal place to express ms as seconds:


C] echo %ms:~0,-2%.%ms:~-2,2%
123.45

C] echo %m2:~0,-2%.%m2:~-2,2%
12.34

C] set m1=123

C] echo %m1:~0,-2%.%m1:~-2,2%
1.23

C] set m0=23

C] echo %m0:~0,-2%.%m0:~-2,2%
.23

C] set m=2

C] echo %m:~0,-2%.%m:~-2,2%
.2

C] set m=02

C] echo %m:~0,-2%.%m:~-2,2%
.02

To insert commas, not so simple:

C]  set m=123456789

C]  echo %m%
123456789

C] echo %m:~-3,3%
789

C] echo %m:~-6,3%,%m:~-3,3%
456,789

C]  echo %m:~-9,3%,%m:~-6,3%,%m:~-3,3%
123,456,789

C]  echo %m:~-12,3%,%m:~-9,3%,%m:~-6,3%,%m:~-3,3%
123,123,456,789


More complex solutions at https://stackoverflow.com/questions/28700043/thousands-separator-of-an-integer-value


C]  echo %m%
123456789

C]  if %m% GTR 99999999 (set c=%m:~-9,3%,%m:~-6,3%,%m:~-3,3%)C]  echo %c%
123,456,789

C]  set n=12345

C]  if %n%  GTR 99999999 (set c=%n:~-9,3%,%n:~-6,3%,%n:~-3,3%) else ( if %n% GTR 9999 (set c=%n:~-6,3%,%n:~-3,3%) )

C]  echo %c%
123,345       WRONG!!

Wednesday, March 18, 2020

Using RegExp in Notepad++ to convert all RollingFileAppender to DailyRollingFileAppender in a log4j.properties file

1) Change RollingFileAppender to DailyRollingFileAppender

Search for

log4j.RollingFileAppender

Replace with

log4j.DailyRollingFileAppender


2) To comment out the MaxFileSize line:

Search for

log4j\.appender\.[a-zA-Z]+\.MaxFileSize

Replace with

#$&

This works because $& matches the entire expression matched.
(Commenting out instead of deleting in case you want to go back to Rolling.)

3) To comment out the MaxBackupIndex line:

Search for

log4j\.appender\.[a-zA-Z]+\.MaxBackupIndex

Replace with

#$&


4) To insert the DatePattern='.'yyyy-MM-dd line just before existing log4j.appender.SOMETHING.layout= line:

Search for

(log4j\.appender\.[a-zA-Z]+\.)layout=

Replace with

${1}DatePattern='.'yyyy-MM-dd\n$&

This works because:
The parentheses marking from "log4j" to just before "layout" marks out the part returned by ${1}
Then the "\n" adds a newline
Then the $& restores the beginning of the layout= line.

 

-->