Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    India
    Posts
    41

    Unanswered: Hi need help in shell script

    Hi
    I want to replace a perticular word say "Console" with "DEBUG" present in the file.The word may appear any number of times in the file.

    I tried to solve the problem using tr command.

    tr "$wordtosearch" "$wordtoreplace" < $Filename| cat > $Filename


    But it is not giving the output which i want.



    Pls reply back Immediately.


    Regds,
    Arun

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    The tr command deletes or substitutes characters from standard input and writes the result to standard output.

    If you execute the command "tr 'Console' 'DEBUG'", you substitute characters 'C','o','n','s','o','l','e' by 'D','E','B','U','G','',''
    For example :
    Input: La Console systeme
    Output: La DGBUGle UyUteme

    Use sed or perl:
    Code:
    sed "s/$wordtosearch/$wordtoreplace/g"  input_file > temp_file
    mv temp_file input_file
    
    perl -p -i -e "s/$wordtosearch/$wordtoreplace/g" input_file
    If the character '/' is part of one of the two strings (search or replace), you must change it by another, for example :
    Code:
    sed "s!$wordtosearch!$wordtoreplace!g" input_file > output_file
    Jean-Pierre.

  3. #3
    Join Date
    Mar 2004
    Location
    India
    Posts
    41
    Thanks Aigles for ur timely response.

Posting Permissions

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