Linux下使用shell改文件内容

#!/bin/sh
#Parameter Check
if [ $# -ne 1 ]; then
  echo "Usage: `basename $0` newIp"
  echo "Examples:"
  echo " `basename $0` 172.60.0.128"
  exit 1
fi

JNLP_NAME="runClient.jnlp"
TEMP_NAME="temp.jnlp"
IP_REGR="[0-9]/{1,3/}.[0-9]/{1,3/}.[0-9]/{1,3/}.[0-9]/{1,3/}"
SED_PARAM='s/'${IP_REGR}':/'$1':/g'

echo $1 | grep "^"${IP_REGR}"$" > /dev/null
if [ $? -ne 0 ]; then
  echo "Usage: `basename $0` newIp"
  echo "Examples:"
  echo " `basename $0` 172.60.0.128"
  exit 1
fi

#reconfig ip to temp file
sed ${SED_PARAM} ${JNLP_NAME} > ${TEMP_NAME}

#remove JNLP file
rm -f ${JNLP_NAME}

#rename temp file to JNLP File
mv ${TEMP_NAME} ${JNLP_NAME}


 

你可能感兴趣的:(linux,shell,File)