From a870c1f2c9dfeadbcf31d6d6a2371acc3c0727af Mon Sep 17 00:00:00 2001 From: Mic Neale Date: Tue, 14 Nov 2023 16:44:03 +1100 Subject: [PATCH] adding some helper script to combine the content --- content/cat.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 content/cat.sh diff --git a/content/cat.sh b/content/cat.sh new file mode 100755 index 0000000..b595de7 --- /dev/null +++ b/content/cat.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Create an empty file for the final output +output_file="concatenated_output.txt" +> "$output_file" + +# Loop through all .txt files in the current directory +for file in *.txt; do + # Check if the file is not the output file to avoid self-inclusion + if [ "$file" != "$output_file" ]; then + # Add the file name as a header + echo "File: $file" >> "$output_file" + echo "----------------" >> "$output_file" + + # Process the file content + while IFS= read -r line; do + # Check for the separator "-----" + if [[ "$line" == *"-----"* ]]; then + # Replace the separator with "Answer:" + echo "Content:" >> "$output_file" + else + # Add "Question:" only before the first line of the file content + if [[ ! $question_added ]]; then + echo "Topic:" >> "$output_file" + question_added=true + fi + echo "$line" >> "$output_file" + fi + done < "$file" + unset question_added + + # Add a separator between files + echo -e "\n\n-----\n\n" >> "$output_file" + fi +done + +echo "Concatenation complete. Output is in $output_file"