-
Notifications
You must be signed in to change notification settings - Fork 0
/
acro-sub.awk
39 lines (39 loc) · 1.69 KB
/
acro-sub.awk
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
#!/usr/bin/awk -f
#------------------------------------------------------------------------------#
# Programmed By Liz #
#------------------------------------------------------------------------------#
# acronym expansion
# using regular expressions
# RSTART & RLENGTH generated by match()
#===============================================================================
BEGIN {
fil=ENVIRON["HOME"]"/data/acr-sub.dat" # load acronym expansion array
while((getline < fil))
{
split($0,a,"\t") # split line -> array
acro[a[1]]=a[2] # use acronym as index
}
}
#===============================================================================
{
p="" # print build string
for(i=1;i<=NF;i++) # scan words
{
if(match($i,/[A-Z]{2,}/)) # acronym = 2 or more caps
{
s=substr($i,RSTART,RLENGTH) # if acronym has punctuation
p=p sprintf("%s (%s) ",$i,acro[s]) # acronym (expansion)
}
else # normal word
p=p sprintf("%s ",$i)
}
sub(/ $/,"",p) # remove trailing space
print p # print line
}
#===============================================================================
END {
}
#===============================================================================
# functions
#-------------------------------------------------------------------------------
#===============================================================================