» Shell trick: CRLF to LF
I do this again and again in RPM .spec files, so just in case: a little trick to remove the CR from CRLF ;) (Windows uses two bytes for end-of-line markers, namely CR and LF, while Linux and Unix only use one: LF)
You might of course use dos2unix or recode, but this one works in-place, which means that you don't need to make a copy, work on the copy and then copy (heh) that file back onto the original -- here is how to do it with
dos2unix
: cp file file.orig && dos2unixAnd here the shorter version, using sed and its in-place editing feature:file
sed -i 's/\r$//' fileMight as well do it with Perl, which also supports in-place editing:
perl -pi 's/\r$//' fileUpdate: as _Marcus_ just told me,
recode
actually does in-place editing by default, my bad :)
4 Comments:
Thank you for your tips!
btw: dos2unix works in-place as well.
I often need to identify which files in a directory contain CRLFs that need changing to LF. I use the file command to do this:
$ file *.cxx
one.cxx: ASCII C program text
two.cxx: ASCII C program text, with CRLF line terminators
dos2unix also does inplace editing.
Post a Comment
<< Home