Friday, January 24, 2014

Getting rid of Windows line feeds

This script to find infected files:
#!/bin/sh

PATH_TO_SCAN=$1

if [ "${PATH_TO_SCAN}" == "" ]; then
    PATH_TO_SCAN="."
fi

FILELIST=$(find "${PATH_TO_SCAN}" |egrep '\.(java|xml|js|groovy|sql|csv|txt|py)$')

IFS_BCK=$IFS
IFS="
"

for FILEPATH in ${FILELIST}; do
    cat -v "${FILEPATH}" | grep -I -q '\^M'
    if [ $? -eq 0 ]; then echo $FILEPATH; fi
done
IFS=$IFS_BCK


In Eclipse: Windows Preferences, then search "encoding" and set "line terminator" to Unix and Encoding to UTF-8

To convert infected files, in Eclipse do "File/Convert line terminator to..."

Otherwise, in Notepad++ use "edit /EOL conversion"



No comments: