# [SCRIPT] chomp: trim trailing whitespace

11 messages from 2006-05-27 to 2006-05-28. Participants: Jeff Garzik, Jan Engelhardt, Thomas Glanzmann, Neil Brown, Dmitry Fedorov, Martin Langhoff, Linus Torvalds, Keith Owens, Johannes Schindelin.
Thread: https://gitlist.dev/t/4302

## Jeff Garzik, 2006-05-27 02:27

Subject: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <4477B905.9090806@garzik.org>
URL: https://gitlist.dev/e/4477B905.9090806%40garzik.org

```

Attached to this email is chomp.pl, a Perl script which removes trailing 
whitespace from several files.  I've had this for years, as trailing 
whitespace is one of my pet peeves.

Now that git-applymbox complains loudly whenever a patch adds trailing 
whitespace, I figured this script may be useful to others.

	Jeff




```

## Jan Engelhardt, 2006-05-27 10:15

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <Pine.LNX.4.61.0605271212210.6670@yvahk01.tjqt.qr>
URL: https://gitlist.dev/e/Pine.LNX.4.61.0605271212210.6670%40yvahk01.tjqt.qr
In-Reply-To: <4477B905.9090806@garzik.org>

```
> Attached to this email is chomp.pl, a Perl script which removes trailing
> whitespace from several files.  I've had this for years, as trailing whitespace
> is one of my pet peeves.
>
> Now that git-applymbox complains loudly whenever a patch adds trailing
> whitespace, I figured this script may be useful to others.
>

Pretty long script. How about this two-liner? It does not show 'bytes 
chomped' but it also trims trailing whitespace.

#!/usr/bin/perl -i -p
s/[ \t\r\n]+$//



Jan Engelhardt
-- 

```

## Thomas Glanzmann, 2006-05-27 10:24

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <20060527102439.GB26430@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20060527102439.GB26430%40cip.informatik.uni-erlangen.de
In-Reply-To: <Pine.LNX.4.61.0605271212210.6670@yvahk01.tjqt.qr>

```
Hello,

> #!/usr/bin/perl -i -p
> s/[ \t\r\n]+$//

perl -p -i -e 's/\s+$//' file1 file2 file3 ...

        Thomas

```

## Neil Brown, 2006-05-27 10:36

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <17528.11171.347324.526827@cse.unsw.edu.au>
URL: https://gitlist.dev/e/17528.11171.347324.526827%40cse.unsw.edu.au
In-Reply-To: <20060527102439.GB26430@cip.informatik.uni-erlangen.de>

```
On Saturday May 27, sithglan@stud.uni-erlangen.de wrote:
> Hello,
> 
> > #!/usr/bin/perl -i -p
> > s/[ \t\r\n]+$//
> 
> perl -p -i -e 's/\s+$//' file1 file2 file3 ...
> 

Uhm... have either of you actually tried those?  When I tried, I lose
all the '\n' characters :-(

  perl -pi -e 's/[ \t\r]+$//'  *.[ch]

seems to actually work.

NeilBrown

```

## Jeff Garzik, 2006-05-27 11:32

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <447838EB.9060900@garzik.org>
URL: https://gitlist.dev/e/447838EB.9060900%40garzik.org
In-Reply-To: <Pine.LNX.4.61.0605271212210.6670@yvahk01.tjqt.qr>

```
Jan Engelhardt wrote:
>> Attached to this email is chomp.pl, a Perl script which removes trailing
>> whitespace from several files.  I've had this for years, as trailing whitespace
>> is one of my pet peeves.
>>
>> Now that git-applymbox complains loudly whenever a patch adds trailing
>> whitespace, I figured this script may be useful to others.
>>
> 
> Pretty long script. How about this two-liner? It does not show 'bytes 
> chomped' but it also trims trailing whitespace.
> 
> #!/usr/bin/perl -i -p
> s/[ \t\r\n]+$//

Yes, it does, but a bit too aggressive for what we need :)

	Jeff

```

## Dmitry Fedorov, 2006-05-27 11:48

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <7115951b0605270448ge8c45e8ha01c35e6d415e419@mail.gmail.com>
URL: https://gitlist.dev/e/7115951b0605270448ge8c45e8ha01c35e6d415e419%40mail.gmail.com
In-Reply-To: <447838EB.9060900@garzik.org>

```
Jan Engelhardt wrote:
>> Attached to this email is chomp.pl, a Perl script which removes trailing
>> whitespace from several files.  I've had this for years, as
trailing whitespace
>> is one of my pet peeves.

And my scripts.

```

## Jan Engelhardt, 2006-05-27 12:42

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <Pine.LNX.4.61.0605271441080.4857@yvahk01.tjqt.qr>
URL: https://gitlist.dev/e/Pine.LNX.4.61.0605271441080.4857%40yvahk01.tjqt.qr
In-Reply-To: <447838EB.9060900@garzik.org>

```
>> Pretty long script. How about this two-liner? It does not show 'bytes
>> chomped' but it also trims trailing whitespace.
>> 
>> #!/usr/bin/perl -i -p
>> s/[ \t\r\n]+$//
>
> Yes, it does, but a bit too aggressive for what we need :)
>
Whoops, should have been s/[ \t\r]+$//
And the CL form is
  perl -i -pe '...'

Somehow, you can't group it to -ipe, but who cares.


Jan Engelhardt
-- 

```

## Martin Langhoff, 2006-05-27 15:28

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <46a038f90605270828u7842ea48hda07331388694db2@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90605270828u7842ea48hda07331388694db2%40mail.gmail.com
In-Reply-To: <4477B905.9090806@garzik.org>

```
I love perl golf for this kind of stuff... but git-stripspace is part
of git already. Even then, I tend to do it with perl -pi -e ''
constructs ;-)

cheers,


m

```

## Linus Torvalds, 2006-05-27 16:13

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <Pine.LNX.4.64.0605270905190.5623@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0605270905190.5623%40g5.osdl.org
In-Reply-To: <46a038f90605270828u7842ea48hda07331388694db2@mail.gmail.com>

```


On Sun, 28 May 2006, Martin Langhoff wrote:
>
> I love perl golf for this kind of stuff... but git-stripspace is part
> of git already. Even then, I tend to do it with perl -pi -e ''
> constructs ;-)

Well, git-stripspace actually does something slightly differently, in that 
it also removes extraneous all-whitespace lines from the beginning, the 
end, and the middle (in the middle, the rule is: two or more empty lines 
are collapsed into one).

Ie it's a total hack for parsing just commit messages (and it is in C, 
because I can personally write 25 lines of C in about a millionth of the 
time I can write 3 lines of perl).

		Linus

```

## Keith Owens, 2006-05-28 08:33

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <8694.1148805194@ocs3.ocs.com.au>
URL: https://gitlist.dev/e/8694.1148805194%40ocs3.ocs.com.au
In-Reply-To: <Pine.LNX.4.61.0605271441080.4857@yvahk01.tjqt.qr>

```
Jan Engelhardt (on Sat, 27 May 2006 14:42:02 +0200 (MEST)) wrote:
>And the CL form is
>  perl -i -pe '...'
>Somehow, you can't group it to -ipe, but who cares.

-i takes an optional extension which is used to optionally create
backup files.  As such, -i must be followed by space if you want no
extension (and no backup).

```

## Johannes Schindelin, 2006-05-28 10:00

Subject: Re: [SCRIPT] chomp: trim trailing whitespace
Message-ID: <Pine.LNX.4.63.0605281157330.1862@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0605281157330.1862%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <Pine.LNX.4.64.0605270905190.5623@g5.osdl.org>

```
Hi,

On Sat, 27 May 2006, Linus Torvalds wrote:

> Well, git-stripspace actually does something slightly differently, in that 
> it also removes extraneous all-whitespace lines from the beginning, the 
> end, and the middle (in the middle, the rule is: two or more empty lines 
> are collapsed into one).
> 
> Ie it's a total hack for parsing just commit messages (and it is in C, 
> because I can personally write 25 lines of C in about a millionth of the 
> time I can write 3 lines of perl).

But there is no good reason not to add some code and a command line 
switch, so that this tool with a very generic name actually performs what 
a normal person would expect from that name.

Ciao,
Dscho

```
