LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-22-2007, 04:13 PM   #16
Nimoy
Member
 
Registered: Jun 2003
Location: Currently Denmark
Distribution: Ubuntu 11.10
Posts: 334

Original Poster
Rep: Reputation: 30
Weird....


Quote:
Originally Posted by jozyba View Post
Bl**dy Ubuntu!

On Ubuntu 'sh' is symlinked to 'dash', so when you call the script by going 'sh myscript.sh' it will ignore the '#!/bin/bash' at the head of the script and use dash instead. dash cannot cope with the syntax in line 49 of your script.

The solution is either to run it with 'bash myscript.sh' or just to use 'chmod u+x myscript.sh' to make it executable, then call it with './myscript.sh'.
Tried both solutions - No error messages this time. So I presume the syntax is ok as such.

However no changes inside any of the HTML files - Got a .bak file for every file.

Maybe because the script copies the HTML files and doesn't perform the change in every html file ?
 
Old 09-22-2007, 04:27 PM   #17
jozyba
Member
 
Registered: Sep 2007
Distribution: Debian Etch, Lenny, Lenny/Sid
Posts: 31

Rep: Reputation: 15
Quote:
Originally Posted by Nimoy View Post
Tried both solutions - No error messages this time. So I presume the syntax is ok as such.
Well, that's progress.

Quote:
However no changes inside any of the HTML files
The script will only make changes if the *precise* string in the "$substring" variable is found. If no changes are being made, then that substring is not being found. So now it's time for you to check that the substring in your script is correct. If your search clue contains even an extra space or newline character it will not match.
 
Old 09-22-2007, 05:34 PM   #18
Nimoy
Member
 
Registered: Jun 2003
Location: Currently Denmark
Distribution: Ubuntu 11.10
Posts: 334

Original Poster
Rep: Reputation: 30
Working!!!

Changed the substring I wanted to replace - so the script now looks like this:


#! /bin/bash

substring='<a HREF="index.html" TARGET="_top">Home</a> '
replacement='<script type="text/javascript"><!--
google_ad_client = "pub-5045815486985038";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
//2007-08-14: globabilityaug2007setup
google_ad_channel = "5631073777";
google_color_border = "000000";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br><br>
<a HREF="index.html" TARGET="_top">Home</a>'

for file in *.html; do
cp $file $file.bak # alternatively use 'mv'
file_contents="$(<$file.bak)"
echo "${file_contents//$substring/$replacement}" >$file
done

The above was saved into a text file called winner.sh and I have set the perms as you explained earlier in the thread so the script is executable by calling ./winner.sh

HOURS UPON HOURS OF DREARY SYNTAX REPLACEMENT HAVE NOW BEEN SHAVED AWAY FROM MY TIME SPENT MAKING THESE CHANGES - AS WELL AS FUTURE ONES!

THANKS A MILLION!!!!!!!!!!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed not working... culin Programming 26 02-07-2007 05:58 PM
sed command not working right ncsuapex Linux - General 2 04-22-2006 06:27 PM
[SOLVED] working on files with sed and pipe angel115 Linux - Newbie 4 10-23-2005 07:15 PM
Sed command in file not working lbauer Programming 5 04-06-2005 01:31 PM
sed not working if value is passed thru a variable containg value suchi_s Programming 7 10-29-2004 08:41 AM


All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration