Skip to content

Commit 4769582

Browse files
Add text scripts
1 parent 30447cf commit 4769582

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

text-to-one-word-per-line

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# Split a text file to words; print one per line.
4+
#
5+
# Version: 1.0.0
6+
# Created: 2017-05-13
7+
# Updated: 2017-05-13
8+
# License: GPL
9+
# Contact: Joel Parker Henderson ([email protected])
10+
##
11+
set -euf
12+
awk 'awk '{ gsub(/[^[:alnum:][:blank:]]/, ""); for(i=1;i<=NF;i++) print $i }'

text-to-uniq-word-per-line

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
#
3+
# Split a text file to unique words; print one per line.
4+
#
5+
# Example:
6+
#
7+
# ```shell
8+
# $ cat example.txt | text-to-unique-words-per-ilne
9+
# hello
10+
# world
11+
# ```
12+
#
13+
# Example for lowercase:
14+
#
15+
# ```shell
16+
# $ cat example.txt | tr '[:upper:]' '[:lower:]' | ...
17+
#
18+
# Steps for each line:
19+
#
20+
# * Delete non-alphanum characters
21+
# * Remember each word
22+
#
23+
# This script has a goal to run fast, so it does not sort.
24+
#
25+
# Version: 1.0.0
26+
# Created: 2017-05-13
27+
# Updated: 2017-05-13
28+
# License: GPL
29+
# Contact: Joel Parker Henderson ([email protected])
30+
##
31+
set -euf
32+
awk '{ gsub(/[^[:alnum:][:blank:]]/, ""); for(i=1;i<=NF;i++) words[$i]=1} END { for (word in words) { print word; } }'

0 commit comments

Comments
 (0)