File: trim_in.awk

package info (click to toggle)
runawk 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: awk: 1,127; ansic: 736; sh: 420; makefile: 103
file content (40 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
# Written by Aleksey Cheusov <vle@gmx.net>, public domain
#
# This awk module is a part of RunAWK distribution,
#        http://sourceforge.net/projects/runawk
#
############################################################

# =head2 trim_in.awk
#
# As the name of this module says (_in suffix) this module reads and
# potentially changes input lines.
# 
# Leading, ending spaces and/or spaces in the middle of input lines
# are removed depending on TRIM variable.
# TRIM values:
#   "l" - remove leading space characters
#   "r" - remove ending space characters
#   "c" - remove extra space characters in the middle of input lines
#   "lr" - See l and r
#   "lrc" - See l, r and c
#   "lc" - See l and c
#   "cr" - See c and r
# By default TRIM variable is set to "lr". TRIM set to a single space
# character means no trimming.
#

BEGIN {
	if (TRIM == ""){
		TRIM = "lr"
	}
}

{
	if (index(TRIM, "c") > 0)
		gsub(/[ \t][ \t]+/, " ")
	if (index(TRIM, "l") > 0)
		sub(/^[ \t]+/, "")
	if (index(TRIM, "r") > 0)
		sub(/[ \t]+$/, "")
}