-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0372a87
commit 6448ac5
Showing
21 changed files
with
465 additions
and
319 deletions.
There are no files selected for viewing
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
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import argparse | ||
import gzip | ||
import os | ||
|
||
def search_string_in_nt_files(folder_path, search_string): | ||
for root, _, files in os.walk(folder_path): | ||
for filename in files: | ||
if filename.endswith('.gz'): | ||
file_path = os.path.join(root, filename) | ||
try: | ||
with gzip.open(file_path, 'rt', encoding='utf-8') as gz_file: | ||
for line in gz_file: | ||
if search_string in line: | ||
print(line.strip(), filename) | ||
except Exception as e: | ||
print(f"Errore durante la lettura del file {file_path}: {e}") | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Cerca una stringa nei file .gz contenenti file .nt") | ||
parser.add_argument("folder_path", help="Percorso della cartella contenente i file .gz") | ||
parser.add_argument("search_string", help="Stringa da cercare nei file .nt") | ||
|
||
args = parser.parse_args() | ||
folder_path = args.folder_path | ||
search_string = args.search_string | ||
|
||
search_string_in_nt_files(folder_path, search_string) | ||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import argparse | ||
|
||
def find_highest_numbered_file(directory): | ||
highest_numbered_file = None | ||
highest_number = -1 | ||
|
||
for filename in os.listdir(directory): | ||
if filename.endswith(".nt.gz"): | ||
try: | ||
file_number = int(filename.split('.')[0]) | ||
if file_number > highest_number: | ||
highest_numbered_file = filename | ||
highest_number = file_number | ||
except ValueError: | ||
pass | ||
|
||
return highest_numbered_file | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Trova il file con il numero più alto nel nome nella directory.") | ||
parser.add_argument("directory", help="La directory in cui cercare il file con il numero più alto nel nome.") | ||
|
||
args = parser.parse_args() | ||
directory = args.directory | ||
|
||
if not os.path.exists(directory): | ||
print(f"La directory '{directory}' non esiste.") | ||
else: | ||
highest_numbered_file = find_highest_numbered_file(directory) | ||
if highest_numbered_file: | ||
print(f"Il file con il numero più alto nel nome nella directory '{directory}' è: {highest_numbered_file}") | ||
else: | ||
print(f"Nessun file trovato nella directory '{directory}' con numeri nel nome.") |
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
Oops, something went wrong.