sumitasok
4/16/2015 - 9:15 AM

Shell Script collection

Shell Script collection

# find the PID of the process that holds the port specified
lsof -i :7000 | awk 'FNR == 2 {print $2}'

lsof -i :8000 | awk 'FNR == 2 {print $2}' | xargs kill -9
# add a string in a field to line number (15)
perl -pi -e 'if($.==14){s/\n/\n\/\/ ABC\n/g}if(eof){$.=0}' Makefile.txt

# replace regex with environment variable
perl -pi -e 's/(([0-9]+.){3}([0-9]+))/'$dIPmysql'/g' t.sh