我正在使用 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