Stripping line feeds from dos files
Finding the differences between files under DOS is a pain, because DOS does not provide any tools to help manipulate files or streams of files.
When I have source trees I need to compare I use the unix power tool diff
. Sometimes (because of various editor settings) some of the files will have carriage returns and line feeds (DOS style) and some will have just carriage returns (Unix style). This can make finding differences a bit tricky because every line is different.
There is a set of commands called dos2unix
and unix2dos
which helps with stripping (or adding respectively) the line feeds, but on some servers it is not installed. Having just done this with 200 files, I thought I'd share the wealth and give it to the world.
for fn in `find . -type f -name "*.java" -print | sort`
do
echo "$fn"
sed 's/^M//' $fn > $fn.new
mv $fn $fn.old
mv $fn.new $fn
done
Note: that the ^M character is the line feed character. This is obtained by (under bash and most other shells) control+v then press return.
Give things a quick check then delete the originals with:
rm -f `find . -name "*.old"`
Another way to do the same job is to use ed
. Create a new file called line-stripper.vi
with the following lines:
%s/^M//
wq
Where `^M is the linefeed described above. Then just apply that to every file:
for fn in `ls *.hbm.xml`
do
cat line-stripper.vi | ed $fn
done
If there are too many files to delete this way then check out my post on rm: Argument list too long.No feedback yet
Form is loading...