- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Removing ^M characters from the files using sed et...
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-03-2006 10:17 AM
тАО11-03-2006 10:17 AM
How to remove ^M characters from the end of the lines within file/s with
the help of sed/awk or from inside the file openend in vi editor ?
I had noted down earlier somewhere but now it is not handy with me.
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2006 10:22 AM
тАО11-03-2006 10:22 AM
SolutionI think you are remembering this discussion:
https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=974207
In that thread, you will see a Perl offering from me. It works on non-HP platforms in the event that you don't have a 'dos2ux' command as you do on HP-UX.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2006 10:36 AM
тАО11-03-2006 10:36 AM
Re: Removing ^M characters from the files using sed etc..
I had stored this during my previous work place.
Now working for a different company.
Warm Regards,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2006 10:41 AM
тАО11-03-2006 10:41 AM
Re: Removing ^M characters from the files using sed etc..
James has already provided the relevant link to the discussion
but nevertheless i can't stop myself from writing something down:
Just save the following script as for example dos2unix.sh
--------------------------------------------
#!/bin/bash
# To replace dos linebreaks for Unix compatibility
echo "This script will replace the ^M line breaks from dos."
echo -n "Enter filename without extension: "
read file
echo -n "Enter extension: "
read ext
sed 's/\r//' $file.$ext > $file2.$ext
cp -f $file2.$ext $file.$ext
rm -f $file2.$ext
------------------------------------------
to run it, type ./dos2unix.sh
basically, you can just
replace the ^M with sed
sed 's/\r//' xxx.ext > xxx2.ext
then copy xxx2.ext back to the original file xxx.ext
and then remove the file xxx2.ext
thanks
DP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2006 01:04 PM
тАО11-03-2006 01:04 PM
Re: Removing ^M characters from the files using sed etc..
From within the file using vi you can enter the following:
:1,$s/^V^M//
For clarification that's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2006 01:08 PM
тАО11-03-2006 01:08 PM
Re: Removing ^M characters from the files using sed etc..
# dos2ux file1 > file2
This removes the ^M characters that are usually leftovers from a file transfer between Windows and Unix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2006 06:47 PM
тАО11-04-2006 06:47 PM
Re: Removing ^M characters from the files using sed etc..
sed 's/^M$//'
One line == 10 points
regds,
Vinod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2006 07:53 PM
тАО11-05-2006 07:53 PM
Re: Removing ^M characters from the files using sed etc..
just another way:
cp file file.bak
tr -d "^M"
to obtain ^M type ctrl-v, ctrl-m
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2006 09:04 PM
тАО11-05-2006 09:04 PM
Re: Removing ^M characters from the files using sed etc..
# dos2ux soruce_file > result_file
for further:
# man dos2ux
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2006 09:42 PM
тАО11-05-2006 09:42 PM
Re: Removing ^M characters from the files using sed etc..
I always keep handy.
I will upload the full list:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # gsed 3.02.80, but top script is easier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2006 11:02 PM
тАО11-05-2006 11:02 PM
Re: Removing ^M characters from the files using sed etc..
it uses the command dos2ux
dos2ux file >> file2
the new archive will be created without ^M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-06-2006 02:18 AM
тАО11-06-2006 02:18 AM
Re: Removing ^M characters from the files using sed etc..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2019 11:46 AM
тАО04-02-2019 11:46 AM
Re: Removing ^M characters from the files using sed etc..
This actually works. thanks