Professional Web Applications Themes
  1. #1

    Default Re: how to remove a ^M charaters from a variable

    On 12/20/2003 8:21 AM, David Inglis wrote:
    > I am reading in a csv file and it has a control character ^M at the end
    > of each line how can I remove these charaters, I have tried the following
    > and had no success.
    >
    > $a=~s/\^M//;
    > $a=~s/^M//;
    >
    >
    > Any help appreciated thanks.
    >
    >
    ^M is the carriage return. Try s/\x0D//;

    Regards,
    Randy.

    Randy W. Sims Guest

  2. #2

    Default RE: how to remove a ^M charaters from a variable

    tr/015//;

    -Tom Kinzer

    -----Original Message-----
    From: Randy W. Sims [mailto:RandyS@ThePierianSpring.org]
    Sent: Thursday, December 18, 2003 8:05 PM
    To: David Inglis
    Cc: [email]beginners@perl.org[/email]
    Subject: Re: how to remove a ^M charaters from a variable


    On 12/20/2003 8:21 AM, David Inglis wrote:
    > I am reading in a csv file and it has a control character ^M at the end
    > of each line how can I remove these charaters, I have tried the following
    > and had no success.
    >
    > $a=~s/\^M//;
    > $a=~s/^M//;
    >
    >
    > Any help appreciated thanks.
    >
    >
    ^M is the carriage return. Try s/\x0D//;

    Regards,
    Randy.


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Tom Kinzer Guest

  3. #3

    Default RE: how to remove a ^M charaters from a variable

    Hai David,

    I don't where you tried this
    have you tried this in NT or in UNIX?

    $a="jaffer^";
    $a=~s/\^M//; This works in NT
    print $a;

    But it wont works in Unix.

    Try this way in Unix $a=~s/\015//g;

    Let me know if any....

    Thank you
    jaffer


    -----Original Message-----
    From: David Inglis [mailto:inglis4@iinet.net.au]
    Sent: Saturday, December 20, 2003 6:51 PM
    To: [email]beginners@perl.org[/email]
    Subject: how to remove a ^M charaters from a variable



    I am reading in a csv file and it has a control character ^M at the end
    of each line how can I remove these charaters, I have tried the following
    and had no success.

    $a=~s/\^M//;
    $a=~s/^M//;


    Any help appreciated thanks.


    --
    Regards



    David Inglis
    0408502342


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Jaffer Guest

  4. #4

    Default Re: how to remove a ^M charaters from a variable

    Tom Kinzer wrote:
    >
    > tr/015//;
    This will do nothing to the string. It will just return the
    number of zero, one and five characters it finds.

    Control-M is

    "\cM"
    or
    "\x0D"
    or
    "\015"
    or
    "\r"

    To get 'tr' to delete the characters it finds you need the /d
    modifier.

    tr/\015//d

    will do the trick.

    Cheers,

    Rob


    Rob Dixon Guest

  5. #5

    Default RE: how to remove a ^M charaters from a variable

    > Hai David,
    >
    > I don't where you tried this
    > have you tried this in NT or in UNIX?
    >
    > $a="jaffer^";
    > $a=~s/\^M//; This works in NT
    > print $a;
    >
    > But it wont works in Unix.
    Sure it does:
    (unless you're talking goofy data of a binary hexy sort of thing,
    which you might be since I completely missed this post ;p )

    perl -Mstrict -we 'my $v = "HI^MHI";print "$v\n";$v =~ s/\^M//;print "$v\n";'
    HI^MHI
    HIHI

    If you just want to kill the carat and not necessariy 'carat uppercase M' just do
    s/\^//;

    You might want to add a g so it gets them all.

    Dmuey
    >
    > Try this way in Unix $a=~s/\015//g;
    >
    > Let me know if any....
    >
    > Thank you
    > jaffer
    Dan Muey Guest

  6. #6

    Default RE: how to remove a ^M charaters from a variable

    right - my bad. what i mean, not what i say!

    thanks rob.

    -Tom Kinzer

    -----Original Message-----
    From: Rob Dixon [mailto:rob@dixon.port995.com]
    Sent: Friday, December 19, 2003 3:07 AM
    To: [email]beginners@perl.org[/email]
    Subject: Re: how to remove a ^M charaters from a variable


    Tom Kinzer wrote:
    >
    > tr/015//;
    This will do nothing to the string. It will just return the
    number of zero, one and five characters it finds.

    Control-M is

    "\cM"
    or
    "\x0D"
    or
    "\015"
    or
    "\r"

    To get 'tr' to delete the characters it finds you need the /d
    modifier.

    tr/\015//d

    will do the trick.

    Cheers,

    Rob



    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Tom Kinzer Guest

  7. #7

    Default Re: how to remove a ^M charaters from a variable

    > "\r"

    Caveat: Only on *nix systems. Otherwise \n is 0x1512 and not 0x12.

    -Dan


    Dan Anderson Guest

  8. #8

    Default Re: how to remove a ^M charaters from a variable

    On Fri, 2003-12-19 at 11:54, Dan Anderson wrote:
    > > "\r"
    >
    > Caveat: Only on *nix systems. Otherwise \n is 0x1512 and not 0x12.
    That should read Otherwise \n can be 0x1512 -- i.e. on Windoze boxen.
    On Macs it's something different.

    -Dan

    Dan Anderson Guest

  9. #9

    Default Re: how to remove a ^M charaters from a variable

    I'd found this here
    [url]http://www.unixblog.com/quick_unix_tips/remove_m_with_vi.php[/url]
    ------------
    You can try this on multiple files
    perl -pi -e 's/\015//g' files
    ------------




    On Sat, 2003-12-20 at 07:21, David Inglis wrote:
    > I am reading in a csv file and it has a control character ^M at the end
    > of each line how can I remove these charaters, I have tried the following
    > and had no success.
    >
    > $a=~s/\^M//;
    > $a=~s/^M//;
    >
    >
    > Any help appreciated thanks.
    >
    >
    > --
    > Regards
    >
    >
    >
    > David Inglis
    > 0408502342

    ______________________
    Aman Raheja
    AGF Technologies
    [url]http://www.agftech.com[/url]
    ______________________

    Agftech Lists Guest

  10. #10

    Default RE: how to remove a ^M charaters from a variable

    Also to address the root cause, the OP said it was on the end of every line.
    I would check the whole system - depending on the journeys and gyrations the
    CSV file goes through before you get it. An intelligent use of ASCII ftp
    (binary bad) and/or chomp will usually take care of any of the
    cross-platform weirdness on the end of your lines.

    -Tom Kinzer

    -----Original Message-----
    From: agftech lists [mailto:lists@agftech.com]
    Sent: Friday, December 19, 2003 9:00 AM
    To: [email]beginners@perl.org[/email]
    Subject: Re: how to remove a ^M charaters from a variable


    I'd found this here
    [url]http://www.unixblog.com/quick_unix_tips/remove_m_with_vi.php[/url]
    ------------
    You can try this on multiple files
    perl -pi -e 's/\015//g' files
    ------------




    On Sat, 2003-12-20 at 07:21, David Inglis wrote:
    > I am reading in a csv file and it has a control character ^M at the end
    > of each line how can I remove these charaters, I have tried the following
    > and had no success.
    >
    > $a=~s/\^M//;
    > $a=~s/^M//;
    >
    >
    > Any help appreciated thanks.
    >
    >
    > --
    > Regards
    >
    >
    >
    > David Inglis
    > 0408502342

    ______________________
    Aman Raheja
    AGF Technologies
    [url]http://www.agftech.com[/url]
    ______________________


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Tom Kinzer Guest

  11. #11

    Default Re: how to remove a ^M charaters from a variable

    David Inglis wrote:
    >I am reading in a csv file and it has a control character ^M at the end
    >of each line how can I remove these charaters, I have tried the following
    >and had no success.
    >
    >$a=~s/\^M//;
    >$a=~s/^M//;
    >
    >
    >Any help appreciated thanks.
    >
    >
    >
    >
    This is an MS-DOSsy file, where each line is terminated by the famous
    CR/LF combination. "^M" is the carriage return. Between the regex
    slashes ("the jungle") "^" means "beginning of line", so what you have
    instructed regex to do is erase any capital "M" that happens to occur at
    the beginning of a line.

    If you have a copy of the program dos2unix around, it will take care of
    this for you, otherwise you can try $a =~ s/\x0D//;

    which means replace any CR you find with null. HTH.

    Douglas Lentz Guest

  12. #12

    Default Re: how to remove a ^M charaters from a variable

    if its a unix file,.open in vi
    :%s/ctrl+v ctrl+m//g
    (where ctrl+v and ctrl+m gives the ^M character.)

    cheers


    On Fri, 19 Dec 2003, Douglas Lentz wrote:
    > David Inglis wrote:
    >
    > >I am reading in a csv file and it has a control character ^M at the end
    > >of each line how can I remove these charaters, I have tried the following
    > >and had no success.
    > >
    > >$a=~s/\^M//;
    > >$a=~s/^M//;
    > >
    > >
    > >Any help appreciated thanks.
    > >
    > >
    > >
    > >
    > This is an MS-DOSsy file, where each line is terminated by the famous
    > CR/LF combination. "^M" is the carriage return. Between the regex
    > slashes ("the jungle") "^" means "beginning of line", so what you have
    > instructed regex to do is erase any capital "M" that happens to occur at
    > the beginning of a line.
    >
    > If you have a copy of the program dos2unix around, it will take care of
    > this for you, otherwise you can try $a =~ s/\x0D//;
    >
    > which means replace any CR you find with null. HTH.
    >
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    >
    Ajey Guest

Similar Threads

  1. #39251 [NEW]: variable variable class array property is read only
    By taskfreak at gmail dot com in forum PHP Bugs
    Replies: 1
    Last Post: October 25th, 07:08 AM
  2. mysql charaters conversion
    By in forum MySQL
    Replies: 0
    Last Post: November 21st, 10:30 PM
  3. #22237 [Com]: PHP crashes when class references property using variable variable
    By rep at devdomain dot com in forum PHP Development
    Replies: 0
    Last Post: September 29th, 11:34 AM
  4. special HTML charaters in flash
    By Tom Kitta in forum Macromedia Flash
    Replies: 1
    Last Post: August 6th, 07:42 PM
  5. Replies: 1
    Last Post: July 13th, 03:38 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139