Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-14 07:55:41

0001 #!/bin/bash
0002 
0003 # Ensure a file path argument was provided
0004 if [ -z "$1" ]; then
0005     echo "Usage: $0 <filename>"
0006     exit 1
0007 fi
0008 
0009 FILE="$1"
0010 
0011 # Check if the target file actually exists
0012 if [ ! -f "$FILE" ]; then
0013     echo "Error: File '$FILE' not found."
0014     exit 1
0015 fi
0016 
0017 # Check if the first line already starts with #ch
0018 if head -n 1 "$FILE" | grep -q "^#ch"; then
0019     echo "File already contains the '#ch' header. No changes made."
0020 else
0021     # Define the precise header requested
0022     HEADER="#ch,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6"
0023     
0024     # Create a secure temporary file to stage the updates safely
0025     TMP_FILE=$(mktemp)
0026     
0027     # 1. Write the new header to the temporary file
0028     echo "$HEADER" > "$TMP_FILE"
0029     
0030     # 2. Prepend the running number (using awk's NR variable) followed by a comma to each original line
0031     awk '{print NR "," $0}' "$FILE" >> "$TMP_FILE"
0032     
0033     # 3. Safely replace the original file with the modified one
0034     mv "$TMP_FILE" "$FILE"
0035     
0036     echo "Successfully added running channel IDs and header to '$FILE'."
0037 fi