-1
我正在嘗試在一個shell腳本中使用一個sed命令,該腳本在與用戶交互時需要變量,但由於反向引用,我無法使其工作在它使用....一些幫助...?在shell腳本中處理sed命令中的反向引用
腳本:
echo "Origin language?\n"
read ol
echo "\nTarget language?\n"
read tl
echo "\ntmx file name?\n"
read file
然後在sed命令我曾嘗試以下方法:
sed -r "s/lang=\"$ol\">(.*)$/\1/g" "$file" > ${file}_${ol}.txt
sed -r "s/lang=\"$tl\">(.*)$/\1/g" "$file" > ${file}_${tl}.txt
2.
thisol = "<tuv xml:lang=\"$ol\">(.*)$"
thistl = "<tuv xml:lang=\"$tl\">(.*)$"
sed -r "s/$thisol/\1/g" "$file" > ${file}_${ol}.txt
sed -r "s/$thistg/\1/g" "$file" > ${file}_${tl}.txt
thisol = "<tuv xml:lang=\"$ol\">(.*)$"
thistl = "<tuv xml:lang=\"$tl\">(.*)$"
that = "\\\1"
sed -r "s/$thisol/$that/g" "$file" > ${file}_${ol}.txt
sed -r "s/$thistg/$that/g" "$file" > ${file}_${tl}.txt
你需要的,如果你使用雙引號來躲避逆向引用的括號內。如'\(。* \)'。 – tvm
這是我試用過的東西之一,但我再次嘗試,但沒有再次成功...... –
瞭解引用的內容:'sed -E'/ lang ='「$ ol」'>(。*) $/\ 1/g'「$ file」>「$ {file} _ $ {ol} .txt」'。 –