交互式网站app,网站开发中用什么安全性比性比较高,网站建设报价单下载,分销网站开发合同shell脚本单词去重多个文件
例如要求如下#xff1a;
有多个txt文件#xff0c;每个文件内有多行单词 中间为英文的”,”#xff0c;或者中文的”#xff0c;”逗号作为分隔符。
world,世界
set#xff0c;设置
good,好#xff0c;商品
....
将这些文件汇总去除重复…shell脚本单词去重多个文件
例如要求如下
有多个txt文件每个文件内有多行单词 中间为英文的”,”或者中文的””逗号作为分隔符。
world,世界
set设置
good,好商品
....
将这些文件汇总去除重复的单词并输出到一个新的文件内要求可以不区分大小写
实现
#! /bin/bash
#------------------------------------------------------------------------------
# Filename: filterWords.sh
# Usage: ./filterWords.sh ~/test/
# Version: 1.0
# Date: 2018-04-04
# Author: vincent
# Email: N/A
# Description: 此脚本用于过滤多个文件的重复单词保留唯一的单词并输出结果到新的文件
# 忽略大小写如果单词重复随机保留释义
# 支持格式
# set,设置 #英文标点
# set设置 #中文标点
# set,设置集合 #支持多个“,”但是默认第一分隔符前面为单词
# SeT,设置 #支持不许分大小写
# Notes: N/A
#-------------------------------------------------------------------------------declare folderPath$1
declare currentTime$(date %F-%H-%M-%S)
declare outputPath${currentTime}_words.txt
declare wordsCounts0outputMsg()
{if [ $1 -ne 0 ]thenecho $2exit 1fi
}# 检验路径是否为空
if [ -z $folderPath ]
thenfolderPath.
else# 检验路径是否存在if [ ! -d $folderPath ]thenecho ${folderPath} is not existed !exit 1fi
fifileList$(find $folderPath -type f -name *.txt)
outputMsg $? Find txt file failed!
if [[ -z $fileList ]]
thenecho No txt files are found.exit 1
fi# 支持英文的“,”或者中文的“”分隔符,忽略大小写
# 这里在复制代码的时候注意格式最好自己缩短为一行否则很容易出错
# 设置两种分隔符
awk -F[,|] BEGIN{key;}{keytolower($1);words[key]$0}END{for(i in words) print words[i]} $fileList $outputPath
outputMsg $? Filter words failed!wordsCounts$(wc -l $outputPath)
echo Words counts:
echo $wordsCounts