File: space

package info (click to toggle)
pax-utils 1.3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 864 kB
  • sloc: ansic: 10,028; python: 687; sh: 444; makefile: 13
file content (23 lines) | stat: -rwxr-xr-x 359 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh
# Usage: space <file>
# Trim trailing whitespace and consecutive newlines.

i=$1

if [ $# != 1 ] ; then
	cat <<-EOF
	Usage: ${0##/*} <file>
	Trim trailing whitespace and consecutive newlines.
	EOF
fi

sed -E '/[[:space:]]+$/s:[[:space:]]+$::' "$i" | \
	awk '{
	if (NF == 0) {
		while (NF == 0)
			if (getline == 0)
				exit
		print ""
	}
	print
	}'