Skip to content

Commit 5fc353d

Browse files
Initial commit
0 parents  commit 5fc353d

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 DEVANSHU SANGHANI
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ReadME.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# drive_search_script
2+
Script to grep different data from the files present in the directory.

drive_search.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Check for the correct number of arguments
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: drive_search.sh <operation_type> <key_information_type>"
6+
echo "operation_type: 0-search, 1-extraction"
7+
echo "key_information_type: phone, url, email, ip, username"
8+
exit 1
9+
fi
10+
11+
operation=$1
12+
key_info=$2
13+
14+
# Define the regex patterns for different key information types
15+
declare -A regex_patterns
16+
regex_patterns[phone]='(\()?\b[0-9]{3}(?(1)\)[. -]?|[. -]?)[0-9]{3}[. -]?[0-9]{4}\b'
17+
regex_patterns[url]='http://www\..+\.[a-z]{3,4}'
18+
regex_patterns[email]='[a-zA-Z0-9.-]{2,15}@[a-zA-Z0-9]{1,15}\.[a-zA-Z0-9]{3,4}'
19+
regex_patterns[ip]='([0-9]{1,3}\.){3}[0-9]{1,3}'
20+
regex_patterns[username]='^[A-Z][^,]*, [^,]*'
21+
22+
# Perform the search or extraction based on the specified operation type and key information type
23+
case $operation in
24+
0) # Search
25+
if [ "$key_info" == "phone" ]; then
26+
grep -P "${regex_patterns[$key_info]}" ./*
27+
else
28+
grep -E "${regex_patterns[$key_info]}" ./*
29+
fi
30+
;;
31+
1) # Extraction
32+
if [ "$key_info" == "phone" ]; then
33+
cat ./* | strings | grep -P "${regex_patterns[$key_info]}"
34+
else
35+
cat ./* | strings | grep -E "${regex_patterns[$key_info]}"
36+
fi
37+
;;
38+
*)
39+
echo "Invalid operation type. Choose 0 for search or 1 for extraction."
40+
exit 1
41+
;;
42+
esac
43+
44+
45+
exit 0

ss_01.PNG

21.3 KB
Loading

ss_02.PNG

18 KB
Loading

0 commit comments

Comments
 (0)