Sample Header Ad - 728x90

sed in makefile is not working as expected when using regex

1 vote
2 answers
442 views
Got a makefile whith this command which convert folder names on ./cmd/ from snake_case to PascalCase
test:
	@for f in $(shell ls ./cmd/); do \
		echo $${f}; \
 		echo $${f} | sed -r 's/(^|_)([a-z])/\U\2/g'; \
	 done
What I get when I run it is, with a prefixed uppercase U:
api_get_manual
UapiUgetUmanual
And what I expect to get:
ApiGetManual
Asked by Ricardo Albear (143 rep)
Apr 21, 2025, 04:48 PM
Last activity: Apr 23, 2025, 01:52 PM