Page MenuHomePhabricator

FixNewLines.sh

Authored By
clarkson
May 31 2012, 9:35 AM
Size
500 B
Referenced Files
None
Subscribers
None

FixNewLines.sh

#!/bin/sh
newline='
'
for f in h cpp cxx txx
do
filenames=`find . -type f -name "*.${f}"`
number_of_files=`find . -type f -name "*.${f}" | wc -l`
for g in ${filenames}
do
lastline=$(tail -n 1 ${g}; echo x); lastline=${lastline%x}
lastcharacter="${lastline#"${lastline%?}"}"
echo "${lastcharacter}" > /tmp/a.txt
echo "${newline}" > /tmp/b.txt
match=`diff /tmp/a.txt /tmp/b.txt | wc -l`
[ "${match}" != "0" ] && echo >> ${g}
done
done
rm /tmp/a.txt /tmp/b.txt

File Metadata

Mime Type
application/x-shellscript
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
811
Default Alt Text
FixNewLines.sh (500 B)

Event Timeline

Script to add a new line to files without new lines at the end.