Sunday, April 29, 2012

sed Delete / Remove ^M Carriage Return [ Line Feed ]

How can I remove the ^M or ^M (carriage Return / line feed ) from text file using sed under UNIX or Linux operating systems?

Type the following command (to get ^M type CTRL+V followed by CTRL+M):
 
sed -e '/^M/d' input
sed -e '/^M/d' input > output
# gnu sed
sed -i -e '/^M/d' input
 
The substitute command can be used as follows too:
 
sed -e 's/^M//g' input
sed -e 's/^M//g' input > output
# gnu sed
sed -i -e 's/^M//g' input
# replace line feed with FOO
sed -i -e 's/^M/FOO/g' input
 

No comments:

Post a Comment