The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed escape char fed.linuxgossip Shell Programming and Scripting 2 10-04-2008 06:41 AM
How to replace any char with newline char. mightysam Shell Programming and Scripting 5 09-18-2008 08:15 PM
char c = 882 useless79 High Level Programming 1 07-30-2007 05:16 AM
char *p and char p[]. arunviswanath High Level Programming 4 07-20-2006 02:11 AM
\n char in C C|[anti-trust] High Level Programming 1 05-05-2005 06:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
Registered User
 

Join Date: Nov 2008
Posts: 3
Question sed issues with strange char

Hi all,

I try to create a shell script to had the xiti tag at the end of servals web pages just before the <body/> tag.

here is my script :

Code:
#!/bin/bash
##################################################################


rm -R /home/hibern/TEMP/hibern
cp -R /home/hibern/TEMP/hibernorig /home/hibern/TEMP/hibern
value=0

cat << EOF > /tmp/xiti.tmp
<!--\
Xt_param = 's=279747&p=';\
try {Xt_r = top.document.referrer;}\
catch(e) {Xt_r = document.referrer; }\
Xt_h = new Date();\
Xt_i = '<img width="39" height="25" border="0" alt="" ';\
Xt_i += 'src="http://logv33.xiti.com/hit.xiti?'+Xt_param;\
Xt_i += '&hl='+Xt_h.getHours()+'x'+Xt_h.getMinutes()+'x'+Xt_h.getSeconds();\
if(parseFloat(navigator.appVersion)>=4)\
{Xt_s=screen;Xt_i+='&r='+Xt_s.width+'x'+Xt_s.height+'x'+Xt_s.pixelDepth+'x'+Xt_s.colorDepth;}\
document.write(Xt_i+'&ref='+Xt_r.replace(/[<>"]/g, '').replace(/&/g, '$')+'" title="Internet Audience">');\
//-->\
</script>\
<noscript>\
Mesure d'audience ROI statistique webanalytics par <img width="39" height="25" src="http://logv33.xiti.com/hit.xiti?s=279747&p=" alt="WebAnalytics" />\
</noscript></a>\
EOF

for file in `find  /home/hibern/TEMP/hibern -name '*.html' -print`
do

export m_tag=`cat /tmp/xiti.tmp`

sed -e 's/<body>/'$m_tag'/g' "$file" > "$file".tmp && mv -f "$file".tmp "$file"
done
and here is my error :-(

Code:
sed: -e expression #1, char 39: unterminated `s' command
thanks in advance for your help
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-20-2008
Registered User
 

Join Date: Dec 2007
Location: Paris
Posts: 761
Try:
Code:
sed -e 's/<body>/'"$m_tag"'/g' "$file" > "$file".tmp && mv -f "$file".tmp "$file"
Reply With Quote
  #3 (permalink)  
Old 11-20-2008
Registered User
 

Join Date: Sep 2008
Location: Chennai,India
Posts: 13
Arrow

Hi,

Check this

sed -e 's/<body>/${m_tag}/g' "$file" > "$file".tmp && mv -f "$file".tmp "$file"




Thanks,

Thangaraju
Reply With Quote
  #4 (permalink)  
Old 11-21-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,772
Code:
sed -e "s/<body>/${m_tag}/g" "$file" > "$file".tmp && mv -f "$file".tmp "$file"
Drop all the single quotes and use double quotes. Remember, single quotes disable parameter expansion. See the following

Code:
[/tmp]$ a='some text'
[/tmp]$ echo $a
some text
[/tmp]$ echo '$a'
$a
[/tmp]$ echo "$a"
some text
Reply With Quote
  #5 (permalink)  
Old 11-21-2008
Registered User
 

Join Date: Nov 2008
Posts: 3
Thanks for your answer, but it's not working :-(

i tried line by line the and i thing this is due to { char. (that' for some thing like a macro)

i have tried with \{ but the problème still their :-(
Reply With Quote
  #6 (permalink)  
Old 11-23-2008
Registered User
 

Join Date: Nov 2008
Posts: 3
Thumbs up Solved

Thanks for your help, my issue is solved, here is the code :

Quote:
#!/bin/bash
##################################################################

rm -R /home/hibern/TEMP/hibern
cp -R /home/hibern/TEMP/hibernorig /home/hibern/TEMP/hibern
cat << EOF > /tmp/xiti.tmp
<!--\
Xt_param='s=279747&p=';\
try {Xt_r = top.document.referrer;}\
catch(e) {Xt_r = document.referrer; }\
Xt_h = new Date();\
Xt_i=\'<img width="39" height="25" border="0" alt=""\';\
Xt_i +=\'src="http:\/\/logv33.xiti.com\/hit.xiti?\'+Xt_param;\
Xt_i += \'\&hl=\'+Xt_h.getHours()+\'x\'+Xt_h.getMinutes()+\'x\'+Xt_h.getSeconds();\
if(parseFloat(navigator.appVersion)>=4)\
{Xt_s=screen;Xt_i+=\'\&r=\'+Xt_s.width+\'x\'+Xt_s.height+\'x\'+Xt_s.pixelDepth+\'x\'+Xt_s.colorDepth ;}\
document.write(Xt_i+\'\&ref=\'+Xt_r.replace(\/[<>"]\/g, \'\').replace(\/&\/g, \'$\')+'" title="Internet Audience">\');\
\/\/-->\
<\/script>\
<noscript>\
Mesure d'audience ROI statistique webanalytics par <img width="39" height="25" src="http:\/\/logv33.xiti.com\/hit.xiti?s=279747&p="\ alt="WebAnalytics" \/>\
<\/noscript><\/a><\/body>
EOF
export m_tag=`cat /tmp/xiti.tmp`
echo "Value for m_tag : "$m_tag
for file in `find /home/hibern/TEMP/hibern -name '*.html' -print`
do
#sed -e 's/<body\/>/'"$m_tag"'/g' "$file" > "$file".tmp && mv -f "$file".tmp "$file"
sed -e 's/<\/body>/\'"$m_tag"'/g' "$file" > "$file".tmp && mv -f "$file".tmp "$file"
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
sed xiti, shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66