- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Removing ^M from string
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 01:17 PM
12-19-2006 01:17 PM
I try this to remove "^M" from a string.. but does not seem to work.. anyone know why??
.....
my $var = "testing123^M";
$var = s/^V^M//;
print "var=$var";
....
Thanks
Henry
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 01:27 PM
12-19-2006 01:27 PM
Re: Removing ^M from string
# dos2ux file1 > file2
will remove all ^M sequences from file1 and save it in file2.
- Tags:
- dos2ux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 01:34 PM
12-19-2006 01:34 PM
Re: Removing ^M from string
I'll like to implement this to control the string parse to a text so i am using perl to do this. Thanks.
Best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 03:04 PM
12-19-2006 03:04 PM
SolutionHenry,
The ^M or 'CR = Carriage Return" is best represented in perl as \r
You could also use the octal code \012.
Compare this with the more common ^J or 'LF = LineFeed'
For that one you know to use \n or \015.
See: http://www.perl.com/doc/manual/html/pod/perlop.html
Look for 'interpolation'
And also check an ascii table. For example:
http://www.asciitable.com/
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 07:00 PM
12-19-2006 07:00 PM
Re: Removing ^M from string
if you run perl under windows, you may have to use 'binmode' before you use 'print'.
In your example, the syntax must be adjusted; I suggest:
...
($var1 = $var) =~ s/\r//;
print $var1;
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 07:05 PM
12-19-2006 07:05 PM
Re: Removing ^M from string
If you want to denote it in CTRL terms, perl offers you \cM, but that is unportable (think EBCDIC), as you now tell exactly which codepoint you use instead of using the correct escape
^V^M is a vi or shell notation. Ctrl-V tells both to take the next character literally. Perl doesn't know about that.
As \r (or \cM) is whitespace, it also falls in that category, and
(my $var = "testing123 \r") =~ s/\s+$//;
will now remove both the \r and the space
Note also that you 'print "var = $var";' will not print a newline unless you used the -l option on perl invocation. That should probably be 'print "var = $var\n";'
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2006 08:07 PM
12-20-2006 08:07 PM
Re: Removing ^M from string
cat
sed -e "s/^V^M//"
- Tags:
- tr