Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Feb 2006 17:29:15 +0100
From:      Kristian Vaaf <vaaf@broadpark.no>
To:        questions@freebsd.org
Subject:   Script to clean text files
Message-ID:  <7.0.1.0.2.20060211172807.0214a4b8@broadpark.no>

next in thread | raw e-mail | index | archive | help

Hello.

Among other things, this script is suppose to add an empty line
at the bottom of a file.

But somehow it always removes the first line in a text file,
how do I stop this?

#!/usr/local/bin/bash
#
#   Remove CRLF, trailing whitespace and double lines.
#   $ARBA: clean.sh,v 1.0 2007/11/11 15:09:05 vaaf Exp $
#
for file in `find -s . -type f -not -name ".*"`; do
	if file -b "$file" | grep -q 'text'; then
		echo >> "$file"
		perl -i -pe 's/\015$//' "$file"
		perl -i -pe 's/[^\S\n]+$//g' "$file"
		
		perl -pi -00 -e 1 "$file"
		echo "$file: Done"
	fi
done

Thanks,
Vaaf




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7.0.1.0.2.20060211172807.0214a4b8>