forked from keephq/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcat.sh
More file actions
executable file
·31 lines (24 loc) · 787 Bytes
/
concat.sh
File metadata and controls
executable file
·31 lines (24 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Usage: ./concat_files_recursive.sh <directory> <output_file>
# Example: ./concat_files_recursive.sh ./my_directory combined_output.txt
# Check if the correct number of arguments is provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <directory> <output_file>"
exit 1
fi
# Assign arguments to variables for readability
DIRECTORY=$1
OUTPUT_FILE=$2
# Check if the directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory $DIRECTORY does not exist."
exit 1
fi
# Create or clear the output file
> "$OUTPUT_FILE"
# Find and concatenate all files recursively
find "$DIRECTORY" -type f | while read -r file; do
echo "Adding $file to $OUTPUT_FILE"
cat "$file" >> "$OUTPUT_FILE"
done
echo "All files have been recursively concatenated into $OUTPUT_FILE."