Last active
March 12, 2024 10:50
-
-
Save leongjs98/aa72dc55fefc0124fc2015dea7bca126 to your computer and use it in GitHub Desktop.
bash script generated by ChatGPT to search lines in input_file that are not included in the directory_to_check and output results in output_file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
input_file="input_list" # Replace with the path to your input file | |
output_file="output_list" # Replace with the desired output file | |
directory_to_check="path/to/hosts" # Replace with the directory you want to check | |
# Create an empty output file or clear existing content | |
echo "" > "$output_file" | |
while IFS= read -r line || [ -n "$line" ]; do | |
# Check if the line is contained in the directory using ripgrep | |
echo -n "testing $line : " | |
if rg -q "$line" "$directory_to_check"; then | |
# If contained, do nothing | |
echo "$line is included." | |
else | |
# If not contained, copy the line to the output file | |
echo "$line is NOT included. Adding to list" | |
echo "$line" >> "$output_file" | |
fi | |
done < "$input_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment