Problem:
I have a bunch of .sql files that have AS myFieldName
aliases. I need to convert all of these to be AS my_field_name
without affecting tbl.myFieldName
in the first part of each line.
ex:
Before: tbl.myFieldName AS myFieldName,
After: tbl.myFieldName AS my_field_name,
I've used this very simple answer: https://stackoverflow.com/a/28795550/20178 to create a sed command to convert myFieldName
to my_field_name
, but it does it for the entire line.
I've tried sed 's/*AS ([a-z0-9])([A-Z])/AS \1_\L\2/g'
(even though I know this wouldn't work for preserving the first part of the line) but it doesn't seem to match anything at all and so doesn't produce any effect.
How do I add AS
as a part of the matching pattern and then match all upppercase letters for replacement?