From owner-freebsd-questions@FreeBSD.ORG Sat Feb 11 16:29:13 2006 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 13CB116A420 for ; Sat, 11 Feb 2006 16:29:13 +0000 (GMT) (envelope-from vaaf@broadpark.no) Received: from osl1smout1.broadpark.no (osl1smout1.broadpark.no [80.202.4.58]) by mx1.FreeBSD.org (Postfix) with ESMTP id A574643D45 for ; Sat, 11 Feb 2006 16:29:12 +0000 (GMT) (envelope-from vaaf@broadpark.no) Received: from osl1sminn1.broadpark.no ([80.202.4.59]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IUJ00ICM74NI580@osl1smout1.broadpark.no> for questions@freebsd.org; Sat, 11 Feb 2006 17:29:11 +0100 (CET) Received: from urban.broadpark.no ([213.187.181.70]) by osl1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IUJ004U174MIJI0@osl1sminn1.broadpark.no> for questions@freebsd.org; Sat, 11 Feb 2006 17:29:11 +0100 (CET) Date: Sat, 11 Feb 2006 17:29:15 +0100 From: Kristian Vaaf To: questions@freebsd.org Message-id: <7.0.1.0.2.20060211172807.0214a4b8@broadpark.no> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT Cc: Subject: Script to clean text files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Feb 2006 16:29:13 -0000 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