Find the answer to your Linux question:
Results 1 to 3 of 3
I have used SED before, but at a basic level... I have a text file with several lines for example.. FRED 123 BERT88 BERT89 BERT90 BERT101 FRED 234 JIM1 JIM2 ...
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    4

    Can I do this in SED??

    I have used SED before, but at a basic level...

    I have a text file with several lines for example..

    FRED 123
    BERT88
    BERT89
    BERT90
    BERT101
    FRED 234
    JIM1
    JIM2 etc

    I want to take the number just behind FRED and stick it on the front of all subsequent lines, so the output is
    FRED 123
    123BERT88
    123BERT89
    123BERT90
    123BERT101
    FRED 234
    234JIM1
    234JIM2 etc

    I am trying to get my head round whether using the hold space can accomplish this.. but I really need to know if I am on to a loser with SED for this..

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try it with awk:

    Code:
    awk '/FRED/{n=$2;print;next}{print n $0}' file

  3. #3
    Just Joined!
    Join Date
    Mar 2010
    Posts
    4
    Thanks... I thought I might need to awk it...

Posting Permissions

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