bash script to edit a file
Writing by shivdev on Sunday, 3 of August , 2008 at 10:48 pm
You can use sed to edit the contents of a file (say, replace ‘old_str’ with ‘new_str’ in the file default.properties and send the result to default.properties.bak).
sed ‘s/old_str/new_str/g’ ./default.properties > ./default.properties.bak
The script below uses the eval command to use variables with sed.
#!/bin/sh
FIND=’old_str’
REPLACE=’new_str’
FILE=./default.propertieseval “sed -e ‘s/$FIND”/”$REPLACE/g’ $FILE > $FILE.bak”
mv -f $FILE.bak $FILE
For more information on sed read sed – An Introduction and Tutorial.
Leave a comment
Category: Linux,Tips and Tricks
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-
No comments yet.
You must be logged in to post a comment.