Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    10

    Unanswered: remove the trailing spaces or charaters after particular format

    Hi
    here is my problem.
    I have a huge file , each and everly line ends with 00/00/0000 ,,,,,,,,,,,,,,,,,,( 18 commas)
    All I need to do is , I have to ignore whatever the spaces or any more commas after that . Or I have to remove the remaining spaces or commas at the end of the line .
    how can i do it using Unix script.

    Your help will be appreciated.
    Thanks
    Vijay

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    pls give a sample input AND a desired output.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Feb 2005
    Posts
    10

    sampledata

    abcdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,
    dsdsdsdssdsasasasasas00/00/0000,,,,,,,,,,,,,,,,,,
    abcsdsdsd sdsdsdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,
    abcdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,

    this the sample data, it is ending with (00/00/0000 and 18 commas ) and some empty spaces
    I need to make it ending with (00/00/0000 and 17 commas) with no spaces at the end.

    Thanks in advance
    vijay

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    nawk -f vijay.awk file

    vijay.awk:
    Code:
    BEGIN {
       PAT="sds00/00/0000,,,,,,,,,,,,,,,,,,[ ]*$"
       PATnew="sds00/00/0000,,,,,,,,,,,,,,,,,"
    }
    $0 ~ PAT {
          sub(PAT, PATnew, $0)
    }
    1
    or with sed:
    Code:
    sed -e 's#\(00/00/0000\)[, ][, ]*$#\1,,,,,,,,,,,,,,,,,#g' file
    Last edited by vgersh99; 02-21-05 at 18:21.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Feb 2005
    Posts
    10

    Thansk a lot vlad

    I greatly appreciate your help and fast response.
    I did in a different method also.
    here is what i did. I removed all trailing spaces in first tiem then I substituted with 00/00/0000 and 18 spaces with 17 spaces.

    your method also works great but it still have the trailing spaces.

    Thank you very much vlad.

    Vijay

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    my version does remove trailing spaces - tested on Solaris's nawk/sed.
    are you sure those are spaces? maybe tabs or control chars?
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

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