- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- commad to remove control M character
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
Discussions
Discussions
Discussions
Forums
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
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
тАО11-11-2005 11:03 AM
тАО11-11-2005 11:03 AM
I have a file which has probably windows format text file. I want to remove ^M (control M) from the begining of the lines in the files.
In the second files i ^M are present in the begining of each lines and somewhere at the end of the lines.
Please suggest hpux command to remove the extra character ^M from both the files.
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 11:13 AM
тАО11-11-2005 11:13 AM
SolutionUsually /usr/bin/dos2ux command does this for you if you have them and it comes with hpux v11.11.
if youare ftp ing these files, you can choose to transfer them in ascii form instead of binary, which will eliminate those pesky ^M characters.
Last but not the least, you can remove them using sed, albeit, I have not tested this solution but I do not see any reason for it not to work. Here it is:
cat SourceFile|sed -e "1,\$s/^M//" > OutputFile
to create the ^M on the line above you first hit ctrl-v then ctrl-m instead of typing it, to give it the actual meaning of the character.
Hope one of these solutions work for you...
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 11:26 AM
тАО11-11-2005 11:26 AM
Re: commad to remove control M character
You could also use the translate command
tr -d \\015 < file > file_cr_stripped
You can also do the substitution while you are editing the file in vi
vi file
then type
Esc:%s/Ctrl+vCR//CR:wqCR
Esc: gets you in command mode
% refers to the whole file
s/
Ctrl+v escapes special keys like Carriage Return (CR) which appears as ^M
Since patternB is empty the CRs get stripped
:wq exits and saves from buffer to file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 12:45 PM
тАО11-11-2005 12:45 PM
Re: commad to remove control M character
If you are running on HP-UX you have 'dos2ux' and 'ux2dos'.
As noted in their man pages, "dos2ux and ux2dos read each specified file in sequence and write it to standard output, converting to HP-UX format or to DOS format, respectively."
If you are *not* on a HP server, you can make strip the carriage returns (^M) with this:
# perl -ni.bak -e 's/\r\n/\n/s;s/\032//s;print' myfile
The above make a backup copy of "myfile" as "myfile.bak" and performs the conversion.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 01:56 PM
тАО11-11-2005 01:56 PM
Re: commad to remove control M character
I normally use dos2unix command to do this.
HTH,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 03:42 PM
тАО11-11-2005 03:42 PM
Re: commad to remove control M character
this question has been asked so many times here. :)
please see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=972302
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 03:49 PM
тАО11-11-2005 03:49 PM
Re: commad to remove control M character
You can use the following methods to remove ^M from a file
In vi, :s/^M//g
Or use sed to do it:
sed 's(ctrl v ctrl m)g//g' old.file > new.file
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 05:17 PM
тАО11-11-2005 05:17 PM
Re: commad to remove control M character
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2005 10:08 PM
тАО11-11-2005 10:08 PM
Re: commad to remove control M character
There are many methods.
1.Using dos2ux command
#dos2ux file1>newfile
2.Using VI
Edit the file using vi, then
:%s/\^M//g
3.Using tr command.
#tr -d \\015 < filename > newfile
You may also use sed for the same purpose.
Regards,
Syam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2005 05:13 PM
тАО11-12-2005 05:13 PM
Re: commad to remove control M character
# strings
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2005 10:45 PM
тАО11-13-2005 10:45 PM
Re: commad to remove control M character
cat filename | sed -e "s/[ctrl-v ctrl-m]//" > newfilename
by [ctrl-v ctrl-m] I mean you should hit ctrl-v then ctrl-m between the first and second "/" (slash).
i have tested and it is working...
Good Luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2005 01:04 AM
тАО11-14-2005 01:04 AM
Re: commad to remove control M character
Simply it can be donw with /usr/bin/dos2ux command,
Ex: If the file name is file1
# cd /usr/bin
# dos2ux file1 > file2
file2 will be result file, which will not have the control characters.
Enjoy,
hth,
Raj