#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Post How to remove codes and commas?


    Hello experts,

    I'm new to Perl and to this forum and also this is my first post.

    I'm trying to achieve the below in both unix and windows using perl.

    Find a pattern and do the following:
    1. Remove the double codes in the line matching the pattern.
    2. Remove the comma that comes after "=" (There will be only one = in the line).
    3. Remove the comma if followed by another comma.
    4. Remove the comma at the very end of the line if present.
    5. Remove the blank space between strings.

    Not sure if this can be achieved. If so that would be great.

    Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    1. I don"t know what double codes are
    2.
    Code:
    s/=,/=/g;
    3.
    Code:
    s/,,/,/g;
    4.
    Code:
    s/,$//g;
    5. To remove all white space:
    Code:
    s/\s//g;
    If you want something else please explain.

    These statements will do the changes on the $_ special variable. To use these statements on other variables, you could use something like this:

    Code:
    $string =~ s/,,/,/g;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    Originally Posted by Laurent_R
    1. I don"t know what double codes are
    2.
    Code:
    s/=,/=/g;
    3.
    Code:
    s/,,/,/g;
    4.
    Code:
    s/,$//g;
    5. To remove all white space:
    Code:
    s/\s//g;
    If you want something else please explain.

    These statements will do the changes on the $_ special variable. To use these statements on other variables, you could use something like this:

    Code:
    $string =~ s/,,/,/g;
    Hi Laurent,

    Thanks for your reply. When i say double codes, this "" is what i was refering to. Here is ana example.

    BUSINESSTYPE="","Enterprise","Financial Trading","",""
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    Originally Posted by jawaugh
    Hi Laurent,

    Thanks for your reply. When i say double codes, this "" is what i was refering to. Here is ana example.

    BUSINESSTYPE="","Enterprise","Financial Trading","",""
    For example, If I select businesstype 2,3, the value in the variable looks like below:

    BUSINESSTYPE="","Enterprise","Financial Trading","",""

    The result I'm expecting should look like below:

    BUSINESSTYPE=Enterprise,Financial Trading
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    It is called double quotes, not double codes.

    Code:
    s/"//g;
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    Originally Posted by Laurent_R
    It is called double quotes, not double codes.

    Code:
    s/"//g;
    My bad . Thanks a ton, will test it out and let you know.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    Hi Laurent,

    Worked perfectly. Thanks again.

IMN logo majestic logo threadwatch logo seochat tools logo