-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeWordlists.sh
executable file
·77 lines (60 loc) · 1.56 KB
/
mergeWordlists.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/bash
#Combine multiple .txt wordlists into a single wordlist with no duplicate entries.
#Store the separate wordlists in the same directory and execute this script within that directory.
#Retrieve all the text files within the directory.
#Ignore hidden files.
if [ $# -lt 1 ]
then
echo -e "Merge files by Patrick Gatiri. \n"
echo -e "Usage : ./mergeFiles directoryName"
echo -e "Example : ./mergeFiles ."
exit 1
fi
directory=$1
directoryName=$( sed 's/\/$//g' <<< $directory )
if ! [ -d $directoryName ]
then
"Directory ${directoryName} not found"
exit 1
fi
mapfile -t files < <(ls -la $directoryName | sed 1,3d | awk '{print $NF}' | sed '/^\./d' | sed -n '/\.txt$/p')
numberOfFiles=${#files[@]}
if [ $numberOfFiles -eq 0 ]
then
echo "There are no text files to merge"
exit 1
fi
echo -e "Merging ${numberOfFiles} .txt files in ${directoryName}"
mergeFile=""
if [ -e "${directoryName}/mergeFile" ]
then
if [ -e "${directoryName}/mergeFile-50" ]
then
echo "Final files have reached limit. Please delete some and try again"
exit 1
else
for i in {1..50}
do
if [ -e "${directoryName}/mergeFile-${i}" ]
then
continue
else
mergeFile="${directoryName}/mergeFile-${i}"
break
fi
done
fi
else
mergeFile="${directoryName}/mergeFile"
fi
touch $mergeFile
touch tempFile
#Dump the content of all the text files into a single file.
for (( i=0; i<${#files[@]}; i++))
do
cat "$directoryName/${files[i]}" >> tempFile
done
sort -u tempFile >> $mergeFile
rm tempFile
echo -e "\nDone. Merged results can be found in ${mergeFile}"
exit 0