Regular Expression to minimum(non-greedy) matching

If we would like to match multiple duplicate content in the same line, we would like to use minimum match by using RE.

for example:

filename: text

pillar[‘abc’]
pillar[‘abc’]
pillar[‘abc’]}pillar[‘wx’]||pillar[‘yz’]
pillar[‘abc’]

1. matched expression python

import re

f=open('./text','r').read()
# non-greddy result:

print(re.findall('(pillar\[.*?\])',f))

# ourput: ["pillar['abc']", 
"pillar['abc']", 
"pillar['abc']", 
"pillar['wx']", 
"pillar['yz']", 
"pillar['abc']"]

# greedy match result:

print(re.findall('(pillar\[.*\])',f))

#output: ["pillar['abc']", 
"pillar['abc']", 
"pillar['abc']}pillar['wx']||pillar['yz']", 
"pillar['abc']"]

 

2. matched expression using shell

grep -o -P "pillar\['.*?'\]" text

# output: 
pillar['abc']
pillar['abc']
pillar['abc']
pillar['wx']
pillar['yz']
pillar['abc']

How to use privileges port less than 1024 with non-root user

original url: https://blogs.oracle.com/sduloutr/binding-a-server-to-privileged-port-on-linux-wo-running-as-root

Using setcap command, for example, if you tomcat run with 80 with user tomcat

# setup the net bind program
setcap 'cap_net_bind_service=+epi' $JAVA_HOME/bin/java
# start tomcat
systemctl start tomcat
# check port
netstat -ant |grep 444
tcp        0      0 0.0.0.0:444             0.0.0.0:*               LISTEN

All done!