Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    15

    Unanswered: inserting numbers

    I would like to insert "echo" followed by a number, but have the number sequentially increase on each line so that I can track where the computer is through my script. So I can pinpoint possible errors with data or my script.

    eg, I want to make

    line
    line
    line
    line
    line
    ....

    into,

    line
    echo 1
    line
    echo 2
    line
    echo 3
    line
    echo 4
    line
    echo 5....

    Is this possible using sed?
    thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    32
    I don't think you can do that with sed, but you can do it with awk.

    Code:
    awk '{printf("%s\necho %d\n", $0, ++count)}' file
    <edit>
    It occurs to me that this might also work
    Code:
    awk '{printf("%s\necho %d\n", $0, NR)}' file
    </edit>



    .
    Last edited by hyperbole; 02-06-06 at 11:55.

  3. #3
    Join Date
    Jan 2006
    Posts
    32
    double post
    Last edited by hyperbole; 02-06-06 at 11:53.

  4. #4
    Join Date
    Feb 2006
    Posts
    15
    Excellent, I just tried it - that is just what I was looking for!

    I thought that I was going to only use sed as it is great, but looks like I am going to have to learn awk too

    Thanks

Posting Permissions

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