using sed to edit html
I'm having a problem getting sed usage correct. Im replace html in about 950 file across the server.
checkit=size\=\"30\" value\=\"\'\.\$\_POST\[\'tcf_email\'\] echo $checkit returns > size\="30" value\="\'\.$\_POST\[\'tcf_email\'\] replaceit="size=\"26\" value=\"'.$_POST['tcf_email']" echo $replaceit returns > size="26" value="'.['tcf_email'] find / -name anyfile.php -print0 | xargs -0 sed -i.bakto3 's%$checkit%$replaceit%g Process the file but, doesn't replace the text. I expect its something in checkit. Can someone check it for me and help me correct it? Thanks in advance. |
The single quotes with sed prevent variable expansion. Use double quotes.
|
Quote:
I double-quoted, but that didn't correct it.. still think something is wrong with $checkit.. find / -name anyfile.php -print0 | xargs -0 sed -i.bakto3 "s%$checkit%$replaceit%g" |
You will like this
This might be beneficial for you in future.
Code:
sed "s/mytext/$var/" Code:
sed 's/mytext/'$var'/' Code:
sed 's/mytext/'$var\/ Code:
sed 's/mytext/'$var/ So this may work: Code:
sed s/mytext/$var/ |
Hello tkeyser :)
I don't understand what you want to set $checkit to. The effect of Code:
checkit=size\=\"30\" value\=\"\'\.\$\_POST\[\'tcf_email\'\] If you want to set $checkit to size="30" value="'.$_POST['tcf_email'] then you can use Code:
checkit='size="30" value="'"'.\$_POST['tcf_email']" The best way to see what you have got in $checkit is Code:
echo "'$checkit'" If my assumption about what you want to do is correct we now have what you want in $checkit but you are not out of the woods yet. The "." and "[" characters in $checkit are meaningful to sed. These must be escaped if you want them to be taken literally. I think $checkit must be size="30" value="'\.$_POST\['tcf_email'] but I'm not certain and can't test. You could check this by running the sed command manually. Once you are confident you have the right string for $checkit then you can set it in the script. Here's how to do it if my guess was correct Code:
checkit='size="30" value="'"'\\.\$_POST\\['tcf_email']" Best Charles |
I have a question with sed too.
Say if I had a variable read -p "Enter/Paste the URL >> " t # Input would be something like "http://someplace/somewhere/somehow/" sed -e 's/images\//"${t}"/' someFile.html Since 't' contains '/' and not '\/' "/images/" never gets replaced. How would I go about solving this problem? |
The backslash was used to escape the forward slash, which you were using to separate the input and output patterns. You can use other characters instead of a forward slash to avoid the backslashes.
You can instead use: sed -e 's#images/#'"${t}"'#' someFile.html You still have the same mistake from the previous post in this thread. You have the variable single quoted. The "${t}" is taken literally, including the double quotes. Define the t variable manually. Then enter: set sed -e 's#images/#'"${t}"'# someFile.html Now look at: echo "${@}" to see how the arguments are expanded before being given to the sed command. Reading the bash info manual or the advanced bash scripting guide from the www.tldp.org site might be a good idea. You problems are with bash and not sed. |
All times are GMT -5. The time now is 02:26 PM. |