Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, with sed I want to delete chars before the first "." and after the second "." input: xxxxxxx.20130523_173246.dmp.bz2 output: 20130523_173246 Thanks Marco...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2013
    Posts
    4

    Delete characters with sed


    Hi,
    with sed I want to delete chars before the first "." and after the
    second "."

    input: xxxxxxx.20130523_173246.dmp.bz2
    output: 20130523_173246

    Thanks
    Marco

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,170
    To get rid of the first, use this regular expression: s/^.*[.]//
    To get rid of the second, after the first has been processed, use this: s/[.].*$//
    Now, put back the start and end dots: s/^/./ and s/$/./

    You can either pipeline these expressions, or place them in a sed script. In any case, close study of the sed man pages would not be remiss...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    It is easier with cut
    Code:
    cut -d "." -f2 inputfile
    You must always face the curtain with a bow.

  4. #4
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    280
    a="xxxxxxx.20130523_173246.dmp.bz2";b=$(echo $a|sed "s/^[^.]*.\([^.]*\).*/\1/");echo $b

    Bob's yer uncle

Posting Permissions

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