UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 24th, 2006, 08:17 PM
Dunn Dunn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 4 Dunn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 44 sec
Reputation Power: 0
Shell Scripting Newbie Help

I'm taking an online course, intro to unix, and have another assignment to complete before the semester ends. I understand most of it, but I have hit a brick wall on this one. Basically I have two make two scripts, with the second having an extra parted added which I cannot figure out.

Here is my first script:
Quote:
#!/bin/sh
replacethis=$1
withthis=$2
file=$3
mv $file $file.bak
sed -e "s+$replacethis+$withthis+g" $file.bak

I need to edit this so that it ONLY updates the file IF something was changed i.e. the two files are different. I have a decent understanding of how to use if statements and such in scripting and I've used commands such as "diff" straight in the shell, but I'm not sure how to tell the script if there is a difference or not. I don't necessarily need an answer given to me if that is too much to ask, but any pointers to guide me in the right direction would be great. Thanks in advance for any help!

Reply With Quote
  #2  
Old April 25th, 2006, 05:27 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Posts: 1,100 SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level)SimonJM User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 23 h 53 m 7 sec
Reputation Power: 646
I too am confused. You seem to have three parameters:
1 - a search string
2 - a replacement string
3 - a file to search/replace within

You mention two files, but you only reference one in the script, in effect. You mv the file - in essence doign a rename, thus you have just the one file. So, a bit hard to see if 'they' are different.

The only thing that would make sense would be if what you are after doing is the sed command (and maybe also the mv?) ONLY if the search and replacement strings are different.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Shell Scripting Newbie Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek