Last active
May 29, 2022 21:06
-
-
Save anis016/bc44fb2d471f8b4df28c0248476c12a8 to your computer and use it in GitHub Desktop.
File comparisons that contains words or sentence
This file contains hidden or 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
| #!/usr/bin/env python2.7 | |
| # python getLinesDifferenceBetweenTwoFiles.py --path1=line1.txt --path2=line2.txt | |
| import sys | |
| import os | |
| import argparse | |
| def read_lines_and_compare_files(first_file, second_file): | |
| if not os.path.exists(first_file) or not os.path.exists(second_file): | |
| sys.exit("2 files needs to be passed as a parameters") | |
| lines_first_array = [] | |
| with open(first_file) as first_object: | |
| for line in first_object: | |
| lines_first_array.append(line.strip()) | |
| lines_second_array = [] | |
| with open(second_file) as second_object: | |
| for line in second_object: | |
| lines_second_array.append(line.strip()) | |
| result_first = [] | |
| for item in lines_first_array: | |
| if item not in lines_second_array: | |
| result_first.append(item) | |
| result_second = [] | |
| for item in lines_second_array: | |
| if item not in lines_first_array: | |
| result_second.append(item) | |
| print("list of items that doesn't exist in '{0}' but exists in '{1}'".format(second_file, first_file)) | |
| for item in result_first: | |
| print(item) | |
| print("--------------------------") | |
| print("--------------------------") | |
| print("list of items that doesn't exist in '{0}' but exists in '{1}'".format(first_file, second_file)) | |
| for item in result_second: | |
| print(item) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--path1', dest='file_path1', type=str, help='Add first file path') | |
| parser.add_argument('--path2', dest='file_path2', type=str, help='Add second file path') | |
| args = parser.parse_args() | |
| read_lines_and_compare_files(args.file_path1, args.file_path2) |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # ./getWordDifferenceBetweenTwoFiles.sh a.txt b.txt | |
| first_file=$1 | |
| second_file=$2 | |
| if [[ -z ${first_file} ]] || [[ -z ${second_file} ]]; then | |
| echo "2 files needs to be passed as a parameters" | |
| exit 1 | |
| fi | |
| IFS= read -d '' -r -a lines_first_file < "${first_file}" | |
| IFS= read -d '' -r -a lines_second_file < "${second_file}" | |
| # create a string from the array | |
| lines_first_array="${lines_first_file[*]}" | |
| lines_second_array="${lines_second_file[*]}" | |
| #if [[ "${array[*]}" =~ "${value}" ]]; then | |
| # echo "$value is in array" | |
| #fi | |
| for item in "${lines_first_file[@]}"; do | |
| # if the element in the first file does not exist in the second file then put in the array | |
| if ! [[ "${lines_second_array}" =~ "${item}" ]]; then | |
| result_first+=(${item}) | |
| fi | |
| done | |
| for item in "${lines_second_file[@]}"; do | |
| # if the element in the second file does not exist in the first file then put in the array | |
| if ! [[ "${lines_first_array}" =~ "${item}" ]]; then | |
| result_second+=(${item}) | |
| fi | |
| done | |
| echo "list of items that doesn't exist in '${second_file}' but exists in '${first_file}'" | |
| for item in "${result_first[@]}"; do | |
| echo "${item}" | |
| done | |
| echo "--------------------------" | |
| echo "--------------------------" | |
| echo "list of items that doesn't exist in '${first_file}' but exists in '${second_file}'" | |
| for item in "${result_second[@]}"; do | |
| echo "${item}" | |
| done |
This file contains hidden or 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
| log4j.rootLogger=INFO,RANGER_FILE | |
| log4j.appender.RANGER_FILE=org.apache.log4j.DailyRollingFileAppender | |
| log4j.appender.RANGER_FILE.File=/home/ghost016/Log4j/log4j-rolling-file-appender/events.log | |
| log4j.appender.RANGER_FILE.layout=org.apache.log4j.PatternLayout | |
| log4j.appender.RANGER_FILE.layout.ConversionPattern=%m%n | |
| log4j.appender.RANGER_FILE.DatePattern='.'yyyy-MM-dd-HH-mm | |
| files_array=( $(find "/home/ghost016/Log4j/log4j-rolling-file-appender/" -name "events.log.*" -type f -mmin +10 | sort) ) | |
| for file in "${files_array[@]}"; do | |
| echo "file - ${file}" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment