Spaces:
Sleeping
Sleeping
File size: 900 Bytes
056e156 |
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 |
#!/bin/bash
# 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."
|