[Insight-developers] Remove whitespace script (was Followup: using uncrustify)
M Stauffer (V)
mstauff at verizon.net
Fri Dec 17 15:33:22 EST 2010
Hi Matt,
Here's a fix for OSX, which strip tabs instead of 't'. The use of
[[:blank:]] is hopefully portable.
#!/bin/bash
# strip trailing whitespaces (space and tab) from filenames sent to
stdin or as args # Matt McCormick (thewtex) <matt at mmmccormick.com> #
created 2008 May 01
MYTEMP='_rws_tempfile_'
trap 'rm -f $MYTEMP' SIGINT SIGTERM
stripit() {
echo "stripping $1"
#[:blank:] matches space and tab, on OSX at least
sed 's/[[:blank:]]*$//' "$1" > $MYTEMP
#On OSX (bash) this match space and 't'.
#sed 's/[ \t]*$//' "$1" > $MYTEMP
#This works on OSX to match space and tab, but
# might not be portable?
#sed "s/[ "$'\t'"]*$//" "$1" > $MYTEMP
cp $MYTEMP "$1"
}
if [ $# -gt 0 ]; then
while [ "$1" != "" ]; do
stripit $1
shift
done
else
while read; do
stripit $REPLY
done
fi
rm $MYTEMP
>-----Original Message-----
>From: matthew.m.mccormick at gmail.com
>[mailto:matthew.m.mccormick at gmail.com] On Behalf Of Matthew
>McCormick (thewtex)
>Sent: Wednesday, December 15, 2010 6:43 PM
>To: Michael Stauffer (Circular Logic)
>Cc: ITK-dev-list
>Subject: Re: [Insight-developers] Followup: using uncrustify
>
>On Wed, Dec 15, 2010 at 4:59 PM, Michael Stauffer (Circular Logic)
><mstauff at verizon.net> wrote:
>> Thanks!
>>
>> I'm on OSX and there's a couple things:
>>
>> - the backticks don't work for the assignment of MYTEMP
>
>That's interesting. How about
>
>MYTEMP=$(tempfile)
>
>or maybe 'tempfile' is not installed. Another option is 'mktemp'.
>
>The whole MYTEMP issue was an attempting to make it cross platform, to
>which I apparently failed. If it is known that you have GNU sed, then
>'sed -i' can just be used to edit the file.
>
>>
>> - the script also removes trailing t's. Doh! I remember some
>issues in
>> the past with OSX and sed and control characters, I'll try to fix it
>> tomorrow.
>
>That's weird. Please let me know what you come up with.
>
>Regards,
>Matt
>
>>
>> Cheers,
>> Michael
>>
>>>-----Original Message-----
>>>From: matthew.m.mccormick at gmail.com
>>>[mailto:matthew.m.mccormick at gmail.com] On Behalf Of Matthew
>>>McCormick (thewtex)
>>>Sent: Wednesday, December 15, 2010 12:43 PM
>>>To: Michael Stauffer (Circular Logic)
>>>Cc: ITK-dev-list
>>>Subject: Re: [Insight-developers] Followup: using uncrustify
>>>
>>>Hi Michael,
>>>
>>>Great to here you got it working. Here is a script I use to
>>>remove trailing whitespace:
>>>
>>>#!/bin/bash
>>>
>>># strip trailing whitespaces from filenames sent to stdin or
>>>as args # Matt McCormick (thewtex) <matt at mmmccormick.com> #
>>>created 2008 May 01
>>>
>>>MYTEMP=`tempfile`
>>>trap 'rm -f $MYTEMP' SIGINT SIGTERM
>>>
>>>stripit() {
>>> echo "stripping $1"
>>> sed 's/[ \t]*$//' "$1" > $MYTEMP
>>> cp $MYTEMP "$1"
>>>}
>>>
>>>if [ $# -gt 0 ]; then
>>> while [ "$1" != "" ]; do
>>> stripit $1
>>> shift
>>> done
>>>else
>>> while read; do
>>> stripit $REPLY
>>> done
>>>fi
>>>
>>>rm $MYTEMP
>>>
More information about the Insight-developers
mailing list