现在的位置: 首页 > 综合 > 正文

Linux下使用shell改文件内容

2013年01月27日 ⁄ 综合 ⁄ 共 548字 ⁄ 字号 评论关闭

#!/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}

 

抱歉!评论已关闭.