I have code that contains
#ifdef CEEDLING_TESTS
void scheduler_task_delay_update(uint8_t task_index) {
#else
static void scheduler_task_delay_update(uint8_t task_index) {
#endif
I want to remove everything except
void scheduler_task_delay_update(uint8_t task_index) {
So I created a script:
#!/bin/bash
echo $PWD
for f in $(find src/ -type f)
do
sed -i '/#ifdef CEEDLING_TESTS/d' $f
sed -i '/#else/d' $f
sed -i '/#endif/d' $f
sed -i '/^static/d' $f
done
This works 99% of the time. Except when I have code that starts as
static void run_task(uint8_t task_index) {
This code is not wrapped with ifdef
. How can I differentiate between the two using sed and regex?
Edit: Using an online regex parser this should find the text in question:
sed -i '/#ifdef CEEDLING_TESTS/d' $f
sed -i -E "s/#else.*static/temp/g" $f
Edit 2: Found an example here, tried to recreate:
sed -i -e 's/.*#else(.*)#endif.*/1/' $f