Spaces:
Running
Running
# Loop through each CSV file in the current directory | |
for csv_file in *.csv; do | |
# Check if the file is a regular file | |
if [ -f "$csv_file" ]; then | |
echo "Processing $csv_file..." | |
# Temporary file | |
temp_file=$(mktemp) | |
# Check if the file has a header | |
if head -1 "$csv_file" | grep -q "Submitted By"; then | |
echo "The 'Submitted By' column already exists in $csv_file." | |
continue | |
fi | |
# Add 'Submitted By' column header and 'Baseline' entry for each row | |
awk -v OFS="," 'NR==1 {print $0, "Submitted By"} NR>1 {print $0, "Baseline"}' "$csv_file" > "$temp_file" | |
# Move the temporary file to original file | |
mv "$temp_file" "$csv_file" | |
echo "Column 'Submitted By' added successfully with 'Baseline' entry in each row for $csv_file." | |
fi | |
done | |
echo "All CSV files processed." | |