File: expand.sed

package info (click to toggle)
sedsed 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,008 kB
  • sloc: sed: 37,239; ansic: 2,395; python: 815; sh: 624; makefile: 95
file content (32 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (2)
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
#!/bin/sed -f
#  @(#)14apr89/31aug01 expand.sed by Greg Ubben

/	/!b

# Change the text before a tab to
#   text<MARKER>text<TAB><8 blanks><TAB>
#
s/\([^	]*\)	/\1&        	/g

# Reduce the text between the marker and the tab to less
# than eight characters.  We have to put in 8-(length MOD 8)
# blanks, and this effectively does the modulo operation.
:a
        s/[^	]\{8\}/\a/g
ta

# The buffer is now:
#   text<MARKER><(length MOD 8) characters><TAB><expansion><extra blanks><TAB>
#               `-----------------------------------------'
# Notice that the expansion is 8-(length MOD 8), so the 
# underlined part is exactly nine characters.  That's how
# we discard the extra blanks and the tabs.
#                	
s/\(.\{9\}\) *	/\1/g
	
# We have now:
#         text<MARKER><(length MOD 8) characters><TAB><expansion>
#
# so we discard everything between the marker and the tab
#
s/[^	]*	//g