-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslatel
executable file
·35 lines (33 loc) · 1.64 KB
/
slatel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/awk -f
# slatel - strip leading and trailing empty lines
# Copyright (C) 2019-2021 Erik Auerswald <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This program is similar, but different, to Python's strip() method on
# strings in that empty lines, but not all whitespace, are removed from
# both the beginning and end of the input text file. Leading and trailing
# whitespace in both the first and last non-empty lines are preserved by
# this script.
#
# This script uses the following algorithm:
#
# 1) Do not output (or buffer) anything before reading a non-empty line.
# 2) Delay printing of empty lines until the next non-empty line is found.
#
# The script does not use the [:space:] character class for compatibility
# with ancient mawk versions as found in contemporary Debian and Ubuntu
# GNU/Linux distributions, where mawk 1.3.3 from 1996 is the default Awk.
# This is written in 2019. m(
/^[ \t\r\f\v]*$/{if (found_non_empty) {empty_lines=empty_lines $0 "\n"}}
!/^[ \t\r\f\v]*$/{found_non_empty=1; print empty_lines $0; empty_lines=""}