Skip to content

Instantly share code, notes, and snippets.

@xingty
Created March 3, 2023 12:06
Show Gist options
  • Save xingty/2053af1aa2b5def15f7994f569602563 to your computer and use it in GitHub Desktop.
Save xingty/2053af1aa2b5def15f7994f569602563 to your computer and use it in GitHub Desktop.
用来过滤文本中的单词
#!/bin/bash
# words filter 过滤文本中每一行的单词,忽略句子
do_filter() {
while read -r line || [ -n "$line" ]; do
words_count=$(echo $line | wc -w)
if [[ $words_count -eq 1 ]]; then
echo $line
echo $line >> $output
fi
done < "$1"
sort -u $output -o $output
echo "All of the words in $input are already appended to $output"
}
launch() {
input=$1
output=$2
if [[ -z $input ]]; then
echo "wl [input] [output]"
exit 0
fi
if [[ ! -e $input ]]; then
echo "$input No such file or directory"
exit 0
fi
if [[ -z $output ]]; then
output="$(pwd)/words_filter_$( date '+%Y%m%d%H%M').txt"
fi
do_filter $input $output
}
launch $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment