Find the answer to your Linux question:
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 ...
  1. #1
    Just 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 ?

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    45
    Quote Originally Posted by praba
    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.
    The case-insensitivity flag of «sed» is “i”. This information seems not to be in the english man page.

    Quote Originally Posted by praba
    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.
    Mimic your «sed»-example above:
    Code:
    perl -pe "s/$SCHEMA_NAME/$NEW_SCHEMA_NAME/i" sample.prop > sample1.prop;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...