Find the answer to your Linux question:
Results 1 to 3 of 3
Hi guys,i need to put a certain word infront of 7 sentence after it match a certain word,for example root: hi how are u i am fine do u knw ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25

    Ways to start certain line with a word when it match a certain word?

    Hi guys,i need to put a certain word infront of 7 sentence after it match a certain word,for example

    root:
    hi how are u
    i am fine
    do u knw me
    nope i dont
    nvm
    now
    u knw me

    what i wanted is:

    root:
    root :hi how are u
    root:i am fine
    root:do u knw me
    root:nope i dont
    root:nvm
    root:now
    root:u knw me

    ya is somehw like this,which mean when it match root,the next 7 sentences will need to start with "root:",can sed or awk do this?pls help out,thanks alot!!

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    awk 'c&&c--{print "root:",$0;next};/root/{c=7}1' filename

  3. #3
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    hi thanks alot!i find out another way to do it le..thanks for your solution though

Posting Permissions

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