![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| nawk-how count the number of occurances of a pattern, when don't know the pattern | cyber111 | Shell Programming and Scripting | 2 | 05-11-2008 12:00 AM |
| Pattern searching pattern in c files | murthybptl | Shell Programming and Scripting | 6 | 11-17-2007 06:15 AM |
| complex command substitution | spopuri | Shell Programming and Scripting | 5 | 05-24-2006 05:37 AM |
| pattern match and substitution, can you help? | frustrated1 | Shell Programming and Scripting | 4 | 02-20-2006 05:48 AM |
| Search file for pattern and grab some lines before pattern | frustrated1 | Shell Programming and Scripting | 2 | 12-22-2005 12:41 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
vi/vim : complex pattern substitution
I use vim. I have a lot of SQL queries to write, and am hoping there is some wild command I can use in vim to make this simpler.
From a file that is a list of fields, like the excerpt, for example: Code:
orderdetail.ccntyfips orderdetail.citemord orderdetail.coffdetid Code:
COUNT(DISTINCT(orderdetail.ccntyfips)) as ccntyfips, COUNT(DISTINCT(orderdetail.citemord)) as citemord, COUNT(DISTINCT(orderdetail.coffdetid)) as coffdetid, Code:
:%s/[tablename].[fieldname]/COUNT(DISTINCT([tablename].[fieldname])) as [fieldname],/g
__________________
[url=http://www.glitterchildren.com/phpBB2]GlitterChildren Forums[/url] |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
for anybody with a similiar problem.. i received the issue on another forum:
Code:
%s/orderdetail\.\(.*\)/COUNT(DISTINCT(orderdetail.\1)) as \1,/g
__________________
[url=http://www.glitterchildren.com/phpBB2]GlitterChildren Forums[/url] |
|
#3
|
||||
|
||||
|
Although the solution is found, it's worth mentioning that you can also pipe a file through a command using {!} from within vi, e.g.
Code:
{!}awk -F'.' '{print "COUNT(DISTINCT(" $0 ")) as " $2 ","}'
|
||||
| Google The UNIX and Linux Forums |