什么是Vi编辑器正则表达式?

时间:2016-04-21 21:24:47

标签: vi

我在表格中有很多列。我想替换查询中的所有内容:

select count(distinct a), count(distinct b), count(distinct c), count(distinct d) from table_name;

以类似的方式反映别名:

select count(distinct a) as a, count(distinct b) as b, count(distinct c) as c, count(distinct d) as d from table_name;

3 个答案:

答案 0 :(得分:0)

试试这个:

s/\vdistinct\s(.{1})\)/distinct \1) as \1/g

你必须在开头使用\v来使用群组。

答案 1 :(得分:0)

我在vim中试过这个:

new Vue({ el: '#app', data: { showModal: false, book: { name: "Test", description: "", photo: "" } } ready: () -> this.getBookData() console.log (this.book) methods: { getBookData: () -> self = $(this) $.getJSON 'GGPK4A.json', (data) -> self.book = data } })

替换匹配“distinct”的东西,跟随(第一组)非贪婪匹配的任何东西,然后a)“with”distinct(第一组))为(第一组)“

请注意,地址“1,$”选择文件中的所有行。编辑灵感来自Jerry Jeremiah。

答案 2 :(得分:0)

Using the ex commmand s

s/count(distinct \([[:alpha:]_][[:alpha:]_]*\))/& as \1/g

A more robust example using sed, only substituting lines starting with select.

!sed '/^select/s/count(distinct \([[:alpha:]_][[:alpha:]_]*\))/& as \1/g