Results 1 to 6 of 6

Thread: find & replace globally in unix

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Answers
    14

    find & replace globally in unix

    hi,
    I have a large number of text files where we used <file_name>.
    But my requirement is to replace all <file_name>. with <file_name>_

    eg,

    file1
    Hello world File1.
    Welcome file1.

    file2
    Hello world File2.
    Welcome file2.

    I want out put like:
    file1
    Hello world FILE1_
    Welcome FILE1_
    file2
    Hello world FILE2_
    Welcome file FILE2_

    kindly help...


  2. #2
    Expert Member
    Join Date
    Jan 2008
    Answers
    133

    Re: find & replace globally in unix

    C ? Shell Scripting??


  3. #3
    Junior Member
    Join Date
    Nov 2008
    Answers
    14

    Re: find & replace globally in unix

    Shell script


  4. #4
    Junior Member
    Join Date
    Jul 2006
    Answers
    5

    Re: find & replace globally in unix

    Use Shell Scripting, it's very easier to find & Replace
    Find a sample script for it

    where

    path : Replace /home1//Srikanth/Scripts/ with ur path

    file ext : replace *.txt with u r file extension

    Script (FR.sh)
    ------

    #!/bin/sh

    for i in `find /home1//Srikanth/Scripts/ *.txt`
    do
    vim -c "&#37;s/File./FILE_/g" -c ":wq" $i
    done


  5. #5
    Junior Member
    Join Date
    Nov 2008
    Answers
    14

    Re: find & replace globally in unix

    Thanks for the reply. But the vim command not wrking in my system.


  6. #6
    Junior Member
    Join Date
    Jul 2006
    Answers
    5

    Re: find & replace globally in unix

    Quote Originally Posted by jafar_cse View Post
    Thanks for the reply. But the vim command not wrking in my system.
    Hi

    just give vi inspite of vim it will work


  7.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact