Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:33:15+00:00 2026-05-26T21:33:15+00:00

I am using gvim on windows and have a file with several lines that

  • 0

I am using gvim on windows and have a file with several lines that look like this

Select '305','TableA
Select '313','TableB
Select '313','TableC

I would like to append the following line at the end of each line.

', count(*) from [Tablename] where msgid in (select msgid from mainTable where row_dtm<'17NOV11')

The result should look something like this (Note that the [TableName] is replaced by the actual table name.

Select '305','TableA', count(*) from TableA where msgid in (select msgid from mainTable where row_dtm<'17NOV11')
Select '313','TableB', count(*) from TableB where msgid in (select msgid from mainTable where row_dtm<'17NOV11')
Select '313','TableC', count(*) from TableC where msgid in (select msgid from mainTable where row_dtm<'17NOV11')

I can add append the text at the end by just doing

%s/$/', count(*) from [Tablename] where msgid in (select msgid from mainTable where row_dtm<'17NOV11')/g

But i am stuck as to how i can read the table name and put that in place of [Tablename].

Basically i am just trying to generate several queries. Any ideas?
I know that the table name will always be the text from the end of the line to the first ‘ character but how do i read it and add it to the modified string?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:33:16+00:00Added an answer on May 26, 2026 at 9:33 pm

    You need to do a tiny bit of back referencing.
    Change the search term to:
    \(\a\+\)$ this will match the table name. Surrounding the search term with \( and \) allow it to be referenced in the replace
    Add \1 to your replacement string wherever you want the tablename to appear.
    The result should look like this
    %s/\(\a\+\)$/\1', count(*) from [\1] where msgid in (select msgid from mainTable where row_dtm<'17NOV11')/g

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a subroutine in Perl that should be indented like this: sub GetFiles
I have a font display problem while using gvim in Windows 7 with the
I have a list of URLs stored in a .txt file (I'm using Windows
I'm using eclipse for a few months, I realy like gvim better but eclipse
There is someone in my team that swears by using some kind of GVim
I have used Stata and gVim on Windows for a while now. Recently I
I'v been using vim/gVim so far in my Linux Machine, and I have a
I'm using gvim on Windows. In my _vimrc I've added: set shell=powershell.exe set shellcmdflag=-c
I am using gVim 7.2 on Windows 7. I can set the gui font

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.