Skip to content
This repository was archived by the owner on Mar 30, 2020. It is now read-only.

Commit 24fa564

Browse files
author
Steve Kemp
committed
Added collapse.
This is a trivial utility which I suspect should not be here, but due to popular demand I've added it. This closes #20.
1 parent cc85626 commit 24fa564

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ Example:
6565

6666

6767

68+
collapse
69+
--------
70+
71+
Remove extraneous whitespace from lines, and remove empty-lines entirely.
72+
73+
Example:
74+
75+
$ echo -e "Test1\n f \n\nTest2\n\n\n\n" | ./collapse
76+
Test1
77+
f
78+
Test2
79+
80+
Alternatives:
81+
82+
* `tr`
83+
* ...
84+
85+
86+
6887
dupes
6988
-----
7089

collapse

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env perl
2+
3+
=head1 NAME
4+
5+
collapse - Remove blank-lines, collapsing whitespace.
6+
7+
=cut
8+
9+
=head1 SYNOPSIS
10+
11+
General Options:
12+
13+
--help Show the help information for this script.
14+
--verbose Show useful debugging information.
15+
16+
=cut
17+
18+
19+
=head1 ABOUT
20+
21+
This simple utility script removes blank lines, and lines containing whitespace
22+
from the given files, or STDIN.
23+
24+
The script is designed to be operated as a pipe, rather than upon files, but
25+
despite that it might be useful.
26+
27+
=cut
28+
29+
=head1 AUTHOR
30+
31+
Steve
32+
--
33+
http://www.steve.org.uk/
34+
35+
=cut
36+
37+
38+
=head1 LICENSE
39+
40+
Copyright (c) 2018 by Steve Kemp. All rights reserved.
41+
42+
This script is free software; you can redistribute it and/or modify it under
43+
the same terms as Perl itself.
44+
45+
The LICENSE file contains the full text of the license.
46+
47+
=cut
48+
49+
50+
use strict;
51+
use warnings;
52+
use Getopt::Long;
53+
use Pod::Usage;
54+
55+
56+
#
57+
# Get the options, either defaults or from the command line.
58+
#
59+
my %config = parsedOptions();
60+
61+
#
62+
# Run the action.
63+
#
64+
while (<>)
65+
{
66+
s/(^|\n)[\n\s]*/$1/g;
67+
print;
68+
}
69+
70+
71+
72+
=begin doc
73+
74+
Parse the options and return suitable values.
75+
76+
=end doc
77+
78+
=cut
79+
80+
sub parsedOptions
81+
{
82+
my %vars;
83+
84+
exit
85+
if (
86+
!GetOptions( "help" => \$vars{ 'help' },
87+
"verbose" => \$vars{ 'verbose' } ) );
88+
pod2usage(1) if ( $vars{ 'help' } );
89+
90+
return (%vars);
91+
92+
}

0 commit comments

Comments
 (0)