Certainly! You can achieve this by creating a script that will search through text files and extract contents from RAR files in Termux on a rooted Android device. To do this, you will need to install some utilities in Termux.
Here's a step-by-step guide and a simple script to help you perform this task:
Step 1: Install necessary packages
First, make sure you have Termux installed on your Android device. Then, update your packages and install necessary utilities:
pkg update && pkg upgrade
pkg install grep unrar termux-api
Step 2: Script to search within files
Create a script file, for example, search_files.sh, to perform the search operation.
#!/data/data/com.termux/files/usr/bin/bash
# Check if the user provided a search term
if [ -z "$1" ]; then
echo "Usage: ./search_files.sh search_term"
exit 1
fi
SEARCH_TERM="$1"
TEXT_HITS=0
RAR_HITS=0
# Search inside .txt files
for file in $(find . -type f -name "*.txt"); do
MATCHES=$(grep -i -c "$SEARCH_TERM" "$file")
if [ "$MATCHES" -ne 0 ]; then
echo "Found $MATCHES matches in $file"
TEXT_HITS=$((TEXT_HITS + MATCHES))
fi
done
# Search inside .rar files
for file in $(find . -type f -name "*.rar"); do
TEMP_DIR=$(mktemp -d)
unrar e -inul "$file" "$TEMP_DIR"
for extracted_file in "$TEMP_DIR"/*; do
if [ -f "$extracted_file" ]; then
MATCHES=$(grep -i -c "$SEARCH_TERM" "$extracted_file")
if [ "$MATCHES" -ne 0 ]; then
echo "Found $MATCHES matches in $extracted_file (from $file)"
RAR_HITS=$((RAR_HITS + MATCHES))
fi
fi
done
rm -rf "$TEMP_DIR"
done
TOTAL_HITS=$((TEXT_HITS + RAR_HITS))
# Display the total number of hits
echo "Total matches: $TOTAL_HITS"
# Use termux-tts-speak to give verbal confirmation
termux-tts-speak "Found a total of $TOTAL_HITS matches for the search term $SEARCH_TERM"
Step 3: Make the script executable
Before running the script, make it executable with the following command:
chmod +x search_files.sh
Step 4: Run the script
Now you can run your script with a search term:
./search_files.sh "your_search_term"
Explanation:
-
grep: Searches through .txt files for the specified term. The -i flag enables case-insensitive matching, and -c counts the number of matches.
-
unrar: Extracts files from .rar archives to a temporary directory for searching. The -inul option suppresses the usual output.
-
termux-tts-speak: Provides verbal confirmation of total matches found.
This script should search for the specified term in .txt files and contents of .rar files and then give you a verbal feedback on the number of matches found. Be sure you have allowed Termux access to your device's file system and granted any necessary root permissions.