Results 1 to 4 of 4

Thread: find a word in a file, and change a word beneath it ??

  1. #1
    Member
    Join Date
    Oct 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Unhappy find a word in a file, and change a word beneath it ??

    Hi all,

    I have a file with lines written somewhat like this.

    Code:
    aaaa
    ccc
    aa
    linux
    browse = no
    xssxw
    cdcedc
    dcsdcd
    csdw
    police
    dwed
    dwd
    browse = no
    
    
    cdecec
    dsdc
    cdc
    wd
    
    wdcew
    dwed
    market
    browse = yes
    
    dwdw
    wedwe
    we
    I would like to search word police (which is in middle of file)
    and then change the line from browse = no to browse = yes which is after two lines from the word police.

    Pls help... I am not so advanced in scripting.

    Thanks in advance,
    Vikas

  2. #2
    Member
    Join Date
    Feb 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    7

    Default

    Code:
    sed '/police/,/^browse/ s/no/yes/' filename
    Try that.
    Last edited by agn; 14th February 2008 at 12:28 AM.

  3. #3
    Member
    Join Date
    Oct 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Wink

    Quote Originally Posted by agn View Post
    Code:
    sed '/police/,/^browse/ s/no/yes/' filename
    Try that.

    thanks a lot,
    will try this code & revert.

  4. #4
    Junior Member
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Find a word in a file and replace the entire line

    Hi

    I have a requirement which i don't have sufficient knowledge

    my file has a word policy in 3 line so i need to replace the line with word policy with two new lines as line1policy and line2policy

    can any one help me out

    Thanks in Advance

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. To find and replace in text file
    By nashtech in forum Shell scripting
    Replies: 9
    Last Post: 4th November 2010, 06:05 PM
  2. word search in file
    By chandanperl in forum Coding in General
    Replies: 2
    Last Post: 11th March 2008, 11:16 AM
  3. can not find the username in /etc/passwd file
    By subrata1in in forum Getting started tutorials
    Replies: 5
    Last Post: 27th March 2007, 12:45 PM
  4. can not find user name in /etc/passwd file
    By subrata1in in forum Linux software
    Replies: 2
    Last Post: 26th March 2007, 11:44 AM
  5. user pass word
    By sparky in forum Shell scripting
    Replies: 1
    Last Post: 26th June 2006, 08:19 PM

Posting Permissions

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