shell下的文件修改,替換,插入

下面代碼示例爲平臺切換後的測試case的 轉換的模板

#! /bin/bash

# ./porting_dae_case C357040 C1342490_bmc_dafsdaf.py

echo "this is new case id: $1"
echo "this old case file: $2"
echo "now let's begin porting case"

case_id=$1
orign_case_file=$2
# split string
orign_case_id="$(cut -d'_' -f1 <<<"$orign_case_file")"
orign_case_type="$(cut -d'_' -f2 <<<"$orign_case_file")"

echo $orign_case_file
# porting process
# replace string
sed 's/CBaseCase/CBaseCaseDAE/g' -i $orign_case_file
sed 's/sp/lcc/g' -i $orign_case_file
sed 's/SP/LCC/g' -i $orign_case_file
# case_docstring="888888888888"
#insert_string="s,C135380_C110_ipmi_SendPeerStatusBlock(CBaseCaseDAE ,a $case_docstring"
#sed $insert_string -i $orign_case_file

name_change="s/${orign_case_id}_${orign_case_type}/${case_id}_ipmi/g"
sed $name_change -i $orign_case_file

# insert info head of file
sed -i '1i [Author]: @.com """' $orign_case_file
sed -i "1i [Origin]: ${case_id}"  $orign_case_file
sed -i '1i """[Purpose]:' $orign_case_file

tmp_case_name=${orign_case_file//$orign_case_id/$case_id}
new_case_name=${tmp_case_name//bmc/ipmi}

mv $orign_case_file $new_case_nam


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章