The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-02-2004
Registered User
 

Join Date: Jul 2004
Location: NC USA
Posts: 11
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
I want to go to this:

Code:
COUNT(DISTINCT(orderdetail.ccntyfips)) as ccntyfips,
COUNT(DISTINCT(orderdetail.citemord)) as citemord,
COUNT(DISTINCT(orderdetail.coffdetid)) as coffdetid,
I'm not sure if such a thing can be done with one line of command. Fortunately, all lines will be in the same format.. tablename.fieldname. so I know that I need to do something like:

Code:
:%s/[tablename].[fieldname]/COUNT(DISTINCT([tablename].[fieldname])) as [fieldname],/g
If this is possible what would the proper syntax be?
__________________
[url=http://www.glitterchildren.com/phpBB2]GlitterChildren Forums[/url]
Reply With Quote
Forum Sponsor
  #2  
Old 08-03-2004
Registered User
 

Join Date: Jul 2004
Location: NC USA
Posts: 11
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]
Reply With Quote
  #3  
Old 08-03-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
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 ","}'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0