Results 1 to 2 of 2
I am a newbie .
I am using Enterprise Linux 5.
I need a script which automates the process of modifying contents in a files.
There are a few files ...
- 02-27-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 1
Modiying contents of a file
I am a newbie .
I am using Enterprise Linux 5.
I need a script which automates the process of modifying contents in a files.
There are a few files whose contents need to be modified. For eg in the below file sample.prop the value of the SCHEMA_NAME variable has to be modified from scott to olapsys and the value of DATABASE_NAME has to be modified from orcl to oracle.
sample.prop
SCHEMA_NAME=scott
DATABASE_NAME=orcl
I tried using
sed "s/$SCHEMA_NAME/$NEW_SCHEMA_NAME/" sample.prop > sample1.prop
where SCHEMA_NAME is set to scott and NEW_SCHEMA_NAME is set to olapsys but I was not sure how to modify the contents irrespective of the case like SCOTT or scott should be modified to olapsys.
I am not good in perl either, I tried
perl -pi -e 's/scott/olapsys/g' sample.prop
but here instead of hard coding , I want to pass variables and also it should not be case sensitive.
Which method would be quite easy and what steps should I follow ?
- 02-28-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 45
The case-insensitivity flag of «sed» is “i”. This information seems not to be in the english man page.
Originally Posted by praba
Mimic your «sed»-example above:
Originally Posted by praba
Code:perl -pe "s/$SCHEMA_NAME/$NEW_SCHEMA_NAME/i" sample.prop > sample1.prop;


Reply With Quote