Computing.Net > Forums > Unix > improving my

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

improving my

Reply to Message Icon

Name: amir
Date: December 4, 2003 at 07:44:08 Pacific
OS: unix- solaris
CPU/Ram: sun ultra10
Comment:

Hi all,

I have a script that scan files, find old templet and replace it with new one.

1 #!/bin/ksh
2 # Loop through every file like this
3 for file in file_name
4 do
5 cat $file | sed "s/old_templet/new_templet/g" > $file.new
6 #do a global searce and replace and put the results
7 mv $file.new $file
8 #rename $file.new to original name of file
9 done

1. How can i take the 3 parameters (file name, new templet and old templet) from the command row ?
2. How can add option to add big new templet (that include few rows) instead the old templet.

10x
Amir




Sponsored Link
Ads by Google

Response Number 1
Name: hernandez
Date: December 4, 2003 at 10:17:29 Pacific
Reply:

call the script like this

<script_name> <file_name> <old_templet> <new_templet>

add 3 lines at the start of your script

#!/bin/ksh
file_name=$1
old_templet=$2
new_templet=$3

your sed line needs to be parameterised (if i understand what you are doing)
cat $file | sed "s/$old_templet/$new_templet/g" > $file.new

old_templet and new_templet will be words/strings etc...

is this what you were after?


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: improving my

Need to remove all Dup lines www.computing.net/answers/unix/need-to-remove-all-dup-lines/5712.html

how can I clean the /var/adm/cron/l www.computing.net/answers/unix/how-can-i-clean-the-varadmcronl/7764.html

Performance Improvement www.computing.net/answers/unix/performance-improvement/4514.html