Reputation: 233
I'm trying to convert all the words after AS
in a query with shell script:
SELECT
first_name AS First_Name,
last_name AS Last_Name,
AGE('1990-10-12') AS Person_Age
FROM table1
The output I need is
SELECT
first_name AS first_name,
last_name AS last_name,
AGE('1990-10-12') AS person_age
FROM table1
Upvotes: 0
Views: 47
Reputation: 8791
Using Perl
$ cat aswin.sql
SELECT
first_name AS First_Name,
last_name AS Last_Name,
AGE('1990-10-12') AS Person_Age
FROM table1
$ perl -ne ' { s/\bas\b\s+\b(.+?)\b/AS \L\1\E/gi; print } ' aswin.sql
SELECT
first_name AS first_name,
last_name AS last_name,
AGE('1990-10-12') AS person_age
FROM table1
Upvotes: 1
Reputation: 69396
Using awk
awk '/AS/ {for (i=1; i<=NF; i++) if ($i == "AS") $(i+1) = tolower($(i+1))} {print}' < infile.sql
Upvotes: 1
Reputation: 52536
If you have GNU sed, you can use \L
, an extension to the s
command that converts everything that follows it to lowercase:
$ sed -E 's/(AS)(.*)/\1\L\2/' infile
SELECT
first_name AS first_name,
last_name AS last_name,
AGE('1990-10-12') AS person_age
FROM table1
Upvotes: 3