2013-03-04 22 views
0

嗨,我有一個XML文件,我需要在一行中搜索一個字符串,如果存在替換一些東西,搜索下一個字符串,並用所需的替換。 我想這多行字符串多行的外殼腳本

while read line 
    do 
    user=`echo $LINE |grep "<?xml"` 
    if [ $user == "<?xml" ]; then 
     replace=utf-8 
     user=`echo $LINE|sed "s/UTF-8/${replace}/"` >> $input_file 
    fi 
done 

它正在檢查只有一個字符串,剩餘如何做到這一點。

如何檢查剩下的還喜歡,並做一些檢查和更換。

回答

0

我認爲你的問題在sed命令末尾缺少g標誌。 我也不確定if的狀況。以下是我的例子。

while read line 
    do 
    user=`echo $line |grep "<?xml"` 
    if [ -n "$user" ]; then 
    replace="utf-8" 
    user=`echo $line|sed "s/UTF-8/${replace}/g"` 
    echo $user >> $input_file 
    fi 
done