I want to lowercase all the header filenames in C-Code, but the "/" gets in the way and I can't get it to convert properly using sed and awk or grep commands.
#include
statement is one line long, so I can just lowercase this part, but when I use the canonical conversion 's/before/after/', it doesn't seem to convert properly when there is a "/" in the before and after string, indicating a directory. If you try to escape with " I've tried escaping it with "" but it doesn't work. Is there any way to convert it properly?
CodePudding user response:
Is there any way to convert it properly?
Use some different separator.
sed 's~before~after~'
With GNU sed, you can convert it to lowercase:
sed 's~BEFORE~\L&~'
CodePudding user response:
This is my trial code on GNU. I've tried to exchange sed's separator, but it doesn't work well.
1.textcode for exchanging the header-letter filename:test.c
#include /A/B/INC/HEADER.h
void main(void)
{
int A,B,C,d,e,f;
}
2.Bash code #!/bin/bash echo "start" str1=$(awk "/#include/" test.c) echo $str1 ==> #include /A/B/INC/HEADER.h str2=$(echo ${str1} | tr 'A-Z' 'a-z') echo $str2 ==> #include /a/b/inc/header.h str3='/' str4='s/' str5='g' str6="$str4$str1$str3$str2$str3$str5" ==>s/#include /A/B/INC/HEADER.h/#include /a/b/inc/header.h/g echo $str6 sed -e ${str6} test.c >evi ==> it doesn't work well