Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, I need a really important help with SED Command. I am not good at sed and tried a couple of articles, but I was not able to find ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4

    SED Command help


    Hi All,

    I need a really important help with SED Command. I am not good at sed and tried a couple of articles, but I was not able to find a solution. So need your help.

    I got a file with following text

    "2013-04-24:23:59:59"1366862383,XXXXXX,checkversion,XXXXXX, 2.0.10,XXXXXX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59"1366862398,XXXXXX,checkversion,XXXXXX, 2.0.10,XXXXXX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59"1366862395,XXXXXX,checkversion,XXXXXX, 2.0.10,XXXXXX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59"1366862397,XXXXXX,checkversion,XXXXXX, 2.0.10,XXXXXX,,,Microsoft,11806,,,,local,,,1,US"

    I want to filter this text to
    "2013-04-24:23:59:59,XXXXXX,checkversion,XXXXXX,2.0.10,XXXX XX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59,XXXXXX,checkversion,XXXXXX,2.0.10,XXXX XX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59,XXXXXX,checkversion,XXXXXX,2.0.10,XXXX XX,,,Microsoft,11806,,,,local,,,1,US"
    "2013-04-24:23:59:59,XXXXXX,checkversion,XXXXXX,2.0.10,XXXX XX,,,Microsoft,11806,,,,local,,,1,US"

    Which means I want to remove the numbers between second (") to the first (,).

    It would be grateful if anyone of you can help me with this.

    Thank you for your support/help.

    Regards,
    Susheel.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Code:
    sed -r s'/^(.*)\"([[:digit:]]*),(.*)$/\1,\3/'  < textfile
    Be aware, that the matching is not very precise.
    So depending on the data in the textfile, this regex is enough or not.

    Also, there is a difference in the input and output example, that you didnt mention:
    input : , 2.0.10,XXXXXX,
    output: ,2.0.10,XXXX XX,
    So there is a white space moving between columns.
    The regex does not address this.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    Thank you very much for you help.

    It works perfectly as I needed.

Posting Permissions

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