Loading ...
Sorry, an error occurred while loading the content.

46410Re: Quickest way to lowercase all characters in a file EXCEPT those in single quotes?

Expand Messages
  • Benji Fisher
    Jan 2, 2004
    • 0 Attachment
      On Fri, Jan 02, 2004 at 07:27:47AM -0800, Dennis W. Disney wrote:
      > I asked earlier what is the quickest way to lowercase all characters in
      > a file EXPECT those in single quotes. Let me provide a bit more
      > background - I am trying to write something to reformat SQL generated
      > by a reporting tool. It generates SQL that looks like:
      > SELECT
      > PRODUCT.PRODUCT_NAME,
      > STORE.REGION,
      > SUM(SALES.AMOUNT)
      > FROM
      > PRODUCT,
      > STORE,
      > SALES
      > WHERE
      > ( PRODUCT.PRODUCT_ID=SALES.PRODUCT_ID )
      > AND ( STORE.STORE_ID=SALES.STORE_ID )
      > AND ( PRODUCT.CATEGORY='BEER' )
      > GROUP BY
      > PRODUCT.PRODUCT_NAME,
      > STORE.REGION
      >
      > And I want to reformat the SQL to look like:
      > SELECT product.product_name,
      > store.region,
      > SUM(sales.amount)
      > FROM product,
      > store,
      > sales
      > WHERE product.product_id=sales.product_id
      > AND store.store_id=sales.store_id
      > AND product.category='BEER'
      > GROUP BY product.product_name,
      > store.region
      >
      > My plan is to convert everything that is not between a pair of single
      > quotes into lowercase, then change all of the SQL keywords into
      > uppercase. Next, remove the pointless parenthesis in the WHERE and AND
      > lines. Then, go through the file to get the words lined up as I like.
      >
      >
      > I was going to do this as a plug in, but I couldn't get the plugin to
      > use the \< and \> atoms, which I need to find the SQL keywords. Now, I
      > plan on writing a script file and executing that.

      If you want help with that, provide a more complete description of
      the problem.

      > Back to the initial problem of putting everything in lowercase
      > characters EXCEPT those in single quotes. Benji Fisher suggested:
      [snip]
      > Roberto Bonvallet suggested:
      [snip]

      If you want to do this from a script, I suggest that you do not use
      macros, as in the snipped suggestions. Is it safe to assume that
      strings are always on the same line, or do we have to worry about
      'strings that span
      multiple lines, like this'?

      In your example, the original file is ALL CAPS. Is it safe to
      assume this, or may there be strings with 'mIxEd CaPs' that you want to
      preserve?

      --Benji Fisher
    • Show all 19 messages in this topic