我正在使用 sed -e "s/\*DIVIDER\*/$DIVIDER/g"
用用戶指定的字符串替換*DIVIDER*
,該字符串存儲在$DIVIDER
中。問題是我希望它們能夠將轉義字符指定爲分隔符,如\ n或\ t。當我嘗試這個時,我最後只是寫了字母n或t,等等。使用sed將變量的內容替換爲字符串,即使它是轉義字符
有沒有人有關於如何做到這一點的任何想法?這將不勝感激!
編輯:這是腳本的肉,我必須缺少的東西。
curl --silent "$URL" > tweets.txt
if [[ `cat tweets.txt` == *\<error\>* ]]; then
grep -E '(error>)' tweets.txt | \
sed -e 's/<error>//' -e 's/<\/error>//' |
sed -e 's/<[^>]*>//g' |
head $headarg | sed G | fmt
else
echo $REPLACE | awk '{gsub(".", "\\\\&");print}'
grep -E '(description>)' tweets.txt | \
sed -n '2,$p' | \
sed -e 's/<description>//' -e 's/<\/description>//' |
sed -e 's/<[^>]*>//g' |
sed -e 's/\&\;/\&/g' |
sed -e 's/\<\;/\</g' |
sed -e 's/\>\;/\>/g' |
sed -e 's/\"\;/\"/g' |
sed -e 's/\&....\;/\?/g' |
sed -e 's/\&.....\;/\?/g' |
sed -e 's/^ *//g' |
sed -e :a -e '$!N;s/\n/\*DIVIDER\*/;ta' | # Replace newlines with *divider*.
sed -e "s/\*DIVIDER\*/${DIVIDER//\\/\\\\}/g" | # Replace *DIVIDER* with the actual divider.
head $headarg | sed G
fi
sed的線的長列表中從XML源替換字符,並且最後兩個是應該與指定的字符,以取代換行符的那些。我知道用另一個換行符替換換行符似乎是多餘的,但這是我能想到的最簡單的方法,讓他們選擇他們自己的分頻器。分區替換對於普通字符非常有用。
你的腳本寫的不好。很多不必要的sed步驟。顯示你正在處理的輸入文件,並顯示你想要的輸出。 – ghostdog74 2010-02-13 18:00:30