Insert Text

2008-04-30
2012-11-13
  • Nobody/Anonymous

    I want to take and insert text from one document to a location on antoher for example

    I have a SQL statement like so

    EXEC sp_detach_db '', 'false'

    now i have a list of databases on another  sheet like so (but there are 1,000s of them)

    database1
    database2
    database3

    I want to take the database name and insert it between the ''s like so

    EXEC sp_detach_db 'database1', 'false'
    EXEC sp_detach_db 'database2', 'false'
    EXEC sp_detach_db 'database3', 'false'

    Is there an easy way of scripting this or am I just stuck cutting and pasting?

    Thanks in advance

    C~

     
    • Nobody/Anonymous

      Use regex:
      find: ^(.*)$
      replace: EXEC sp_detach_db '\1', 'false'

      see if it works

       
    • Fool4UAnyway

      Fool4UAnyway - 2008-04-30

      1. You could perhaps create a macro that works on the list of databases, putting the desired texts before and after each database. You could run that macro "until the end of the document" containing the databases.

      2. You could use the Column Editor to achieve the same in a slightly different way, but this would only work completely if all names have the same length.

      - Press CTRL+Home to move the cursor to the top of the list
      - Press and keep holding down the SHIFT button.
      - Press CTRL+End to move the cursor to the end of the list (below the last entry)
      - While still holding the SHIFT button, also press and hold down the ALT button and press the CursorUp button once. You have now selected a column with width 0 at the start of each line.
      - Press ALT+C to open the Column Editor dialog.
      - Choose/click "Text to insert".
      - Enter "EXEC sp_detach_db '" without the double quotes.
      - Press Enter of click OK.

      If the lines all have the same length, that is, the database names all have the same names to start with, you can do the same for the postfix.

      - Press CTRL+Home and then End to move to the end of the first line.
      - Press and keep holding down the SHIFT button.
      - Press CTRL+End to move the cursor to the end of the list (below the last entry)
      - While still holding the SHIFT button, also press and hold down the ALT button and press the CursorLeft button once. You have now selected a column with width 0 at the end of each line.
      - Press ALT+C to open the Column Editor dialog.
      - Choose/click "Text to insert".
      - Enter "', 'false'" without the double quotes.
      - Press Enter of click OK.

      You might perform some actions to get all database names padded with spaces to make all lines of the same lengths to start with. You could remove those spaces after adding the prefix and postfix texts, but this involves just another (re)place action. It is also possible to do it without.

      3. Take a look at this similar question, involving inserting text at the beginning of each line using regular expression (regex) mode of the Find/Replace dialog:

      "Insert Filename and Macro" (Help forum)
      http://sourceforge.net/forum/forum.php?thread_id=1965723&forum_id=331754

      or read this thread:

      "how to append lines with a comma or other characters" (Help forum)
      http://sourceforge.net/forum/forum.php?thread_id=1967758&forum_id=331754

      4. You could also take a look at the Simple Script Plug-In. It has straightforward function to insert text at the beginning and at the end of each line.

      BeginLine(string text): Appends text to the beginning of every line.
      EndLine(string text): Appends text to the end of every line.

      Enclose text in quotes.

      Examples:

      BeginLine("<p>") would put an HTML paragraph tag at the beginning of every line in the document.
      EndLine("</p>") would close the HTML paragraph tag at the end of every line.

      Your script would read:

      BeginLine("EXEC sp_detach_db '")
      EndLine("', 'false'")

      You would run this script on the database names list.

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks