Debian Codegraph @

pair-at-a-time

raw
1 #!/bin/bash -norc
2
3 # Public domain notice for all NCBI EDirect scripts is located at:
4 # https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice
5
6 group_phrases() {
7 uniq |
8 paste -sd "," - |
9 sed -e 's/^+//g' -e 's/+$//g' -e 's/,+,/+/g' -e 's/^,//g' -e 's/,$//g' -e 's/+/ /g'
10 }
11
12 word_pairs() {
13 while read first rest
14 do
15 if [ -z "$rest" ]
16 then
17 echo "$first"
18 continue
19 fi
20 prev=$first
21 for curr in $rest
22 do
23 echo "$prev $curr"
24 prev="$curr"
25 done
26 done
27 }
28
29 word-at-a-time |
30 group_phrases |
31 fmt -w 1 |
32 tr ',' ' ' |
33 word_pairs