2.9 KiB
2.9 KiB
Plan to Remove Markdown Tables After First Header in Specified .md Files
Goal
Remove the markdown table that appears after the first markdown header (## X.Y Title) in 35 specific .md files located in the directory /Users/rico/src/iso27diy-corp/Corpus/Standards/ISO27x/OST/27002/EN. These files contain ISO 27002 control descriptions and have a summary table listing Control type, Information security properties, etc., which needs to be removed.
Analysis
- Affected Files: Identified 35 .md files containing the table starting with
| Control type | Information security properties | Cybersecurity concepts | Operational capabilities | Security domains |. - Table Structure: The table consists of 2-4 lines:
- Header row starting with
| Control type - Separator row
- Data row
- Optionally, an empty row
- Header row starting with
- Location: The table appears immediately after the first
##header (e.g.,## 8.1 User endpoint devices) and before the**Control**section. - Pattern: All affected files follow the pattern where the table ends just before
**Control**.
Approach
Use a Bash script with sed to remove the table lines from each affected file. The sed command will delete lines from the start of the table (| Control type) up to but not including **Control**.
Script
Create and run the following Bash script in the target directory:
#!/bin/bash
# Change to the target directory
cd /Users/rico/src/iso27diy-corp/Corpus/Standards/ISO27x/OST/27002/EN || exit 1
# Loop through all .md files
for file in *.md; do
# Check if the file contains the table
if grep -q "| Control type" "$file"; then
# Remove the table lines: from "| Control type" to just before "**Control**"
sed -i '/^| Control type /,/^\*\*Control$/ { /^\*\*Control$/ !d }' "$file"
echo "Processed $file"
fi
done
echo "Table removal complete."
Steps to Execute
- Navigate to Directory: Change to
/Users/rico/src/iso27diy-corp/Corpus/Standards/ISO27x/OST/27002/EN. - Backup (Optional): Consider backing up the directory before running the script.
- Run Script: Execute the script to process all files.
- Verify: After running, check a few files (e.g.,
a-8.1-User-endpoint-devices.md,a-5.15-Access-control.md) to ensure the table is removed and the**Control**section remains intact.
Risks and Considerations
- Accuracy: The
sedcommand is designed to precisely target the table based on the observed patterns. If any file has unexpected formatting, manual review may be needed. - No Impact on Non-Affected Files: Files without the table will remain unchanged.
- Reversibility: If needed, restore from backup or use version control (assuming the directory is in a git repo).
Expected Outcome
- Tables removed from 35 files.
- Content before and after the table (including
**Control**and subsequent sections) preserved. - No changes to other .md files in the directory.