Last active
February 14, 2024 13:26
-
-
Save jeansymolanza/0c969fa382095e9e09f3ed03178946e1 to your computer and use it in GitHub Desktop.
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 | |
directory="/path/to/directory" # Specify the directory path | |
output_file="/path/to/output/file.txt" # Specify the output file path | |
# Get the current date in the desired format | |
current_date=$(date +%y%m%d) | |
# Clear the output file if it exists | |
> "$output_file" | |
# Loop through files in the directory in alphabetical order | |
while IFS= read -r -d $'\0' file_path; do | |
# Skip directories | |
if [ -d "$file_path" ]; then | |
continue | |
fi | |
# Skip empty files or files with less than 3 lines | |
if [ $(wc -l < "$file_path") -lt 3 ]; then | |
continue | |
fi | |
# Extract lines excluding the first and last lines | |
sed '1d;$d' "$file_path" >> "$output_file" | |
done < <(find "$directory" -type f -print0 | sort -z) | |
# Add the date at the top of the output file | |
sed -i "1i $current_date" "$output_file" | |
# Count the number of lines concatenated (excluding the date line) | |
line_count=$(( $(wc -l < "$output_file") - 1 )) | |
# Add the line count at the bottom of the output file | |
echo "900$line_count" >> "$output_file" | |
# Print a message when the concatenation is complete | |
echo "Concatenation complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment