0

I have a list of table names in Notepad++:

employee
manager
customer
reciepts
customer_details
employee_mapping
manager_employee_mapping

I want each word to be duplicated again in the same line, for example:

employee employee
manager manager
customer customer

And so on. I want to do this to make a SQL script where I have to select tablename as string and table's total count. Like:

select 'employee', count(1) from employee    union
select 'manager', count(1) from manager     union

similarly for all rows. Now, words like select/union/count/,/from can easily be inserted using either ctrl+F or insertion at beginning and end. But getting the table name as a string is tricky.

Is there any way to do this in Notepad++ without doing this manually? This list is just a sample, I have a list of more than 100 tables. Please help out.

Sidhant Gupta
  • 139
  • 14
  • Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – AdrianHHH Feb 21 '22 at 09:02

1 Answers1

3
  • Ctrl+H
  • Find what: ^\w+$
  • Replace with: select '$0', count\(1\) from $0 union
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

^           # beginning of line
\w+         # 1 or more word character [a-zA-Z0-9_], this will be kept in group 0
$           # end of line

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
  • Thank you very much @Toto. It solved my problem instantly. But I still didn't understand the use of ^\w+$. Could you please give me an article to study the use of regex in notepad++. – Sidhant Gupta Jul 18 '21 at 14:32
  • @SidhantGupta: `\w` matches a word character i.e. uppercase letter, lowercase letter, digit or underscore. You'll find usefull information [here](https://www.regular-expressions.info/) – Toto Jul 18 '21 at 16:26