I've inherited a few dozen sql scripts that look like this:
select
column_a,
开发者_StackOverflow社区 column_b,
column_c
from
my_table
To format them so they match the rest of our sql library, I'd like to change them to look like this:
select
column_a
,column_b
,column_c
from
my_table
where the commas start at the beginning of the line instead of at the end. I've taken a few passes at this in Perl, but haven't been able to get it to work just right.
Can any of you Perl gods provide some enlightenment here?
perl -pi.bak -0777 -wle's/,[^\n\S]*\n([^\n\S]*)/\n$1,/g' file1.sql file2.sql ...
The character class is any non-newline whitespace. -0777 causes it to operate on whole files, not lines.
精彩评论