Find the answer to your Linux question:
Results 1 to 3 of 3
Code: echo bml:asl:10.10:1:1 | sed -e 's/^bml:asl:*/bml:asl:30/g' I am trying to get the output as bml:asl:30:1:1 but what i got was bml:asl:3010.10:1:1 Also why won't it work on numbers without ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    1

    sed problem

    Code:
    echo bml:asl:10.10:1:1 | sed -e 's/^bml:asl:*/bml:asl:30/g'
    I am trying to get the output as bml:asl:30:1:1 but what i got was bml:asl:3010.10:1:1 Also why won't it work on numbers without decimals?Running Ubuntu btw,and still new at it and sed.

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    Code:
    echo bml:asl:10.10:1:1 | sed -e 's/^bml:asl:.*10/bml:asl:30/g'
    Be assured I'm not a sed guru, I just babble a little with it. A whole encyclopedia can be written about sed.

    Any sequence as a regular expression is '.*' and not '*' .

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Posts
    1
    Hi
    putting yr string in a file, saved as sedfile, the following did the trick:
    sed -e 's/^.\{14\}/bml:asl:30:/' sedfile
    with sedfile in yr working dir
    as indicated by the other helpful comment you received, there is a different behaviour between * as a shell wildcard and a regex. metacharacter. I remembered the option in <sed> which lets you select exactly N characters, as shown (the syntax is definitely cryptic, I had to look it up). If your numbers grow smaller/bigger, there will be a problem, of course. Maybe then you will want to choose another tool, like <cut> with the -f (fields) option, enabling you to select fields (with : as field delimiter, which you also have to supply as an argument before invoking <cut>
    regards

Posting Permissions

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