Remove CRLF between two expressions

Remove CRLF between two expressions

RossGoodman

    Aug 16, 2005#1

    Hello

    I have a file containing lots of SQL statements.
    These statements are split over a number of lines.
    The format (number of lines etc) is not fixed.
    eg:
    select col1,
    col2
    from table1;

    I would like to find and replace all of the crlf (^p) that are between "select" and ";"

    At present I am searching for ",^p" replacing with "," etc.
    I have tried removing all ^p from small files and then replacing ";" with ";^p"

    Any ideas ?

    Ross

    6,686585
    Grand MasterGrand Master
    6,686585

      Aug 16, 2005#2

      This macro does the job.

      InsertMode
      ColumnModeOff
      HexOff
      Top
      Loop
      Find "select "
      IfNotFound
      ExitLoop
      EndIf
      Find Select ";"
      Find "^p"
      Replace All SelectText ""
      EndSelect
      EndLoop

      Important is the space after Find string "select". UltraEdit V11.10b converts the normal Find "select" command into Find Select "select", if the space is not present in the find string. This is a bug!

      How the macro works:

      First it sets the cursor to top of file.

      Then inside an endless loop, following is executed.

      Search for "select ". If not found, exit loop and macro.

      If found, select everything til next ";" (including "select ") and replace in the selected area all line breaks by nothing.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Nov 03, 2005#3

        Hi,

        I have this same kind of problem but mine is a file created on a UNIX box that every record has a CR/LF at the end. The recipient needs the file with a LF only. I need to somehow remove the CR. I have tried "replace" and it actually deletes the CR , I save it and when I reopen it, it has the CR back again... I don't understand what is going on here.

        Dave

        344
        MasterMaster
        344

          Nov 03, 2005#4

          Hi Dave,

          Did u check if in configuation, "file handling", "automatically convert to DOS fomat" is checked ? :?:
          You might put it to "ask" or "no".

          This is more a general issue than regexp...

          rds Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          6,686585
          Grand MasterGrand Master
          6,686585

            Nov 03, 2005#5

            If you just want to convert a DOS file with CR/LF to a Unix file with only LF use the "DOS to Unix" conversation function from the file menu. You should not use a replace function for that, except you want to convert several DOS files to Unix files with the "Replace In Files" function.
            Best regards from an UC/UE/UES for Windows user from Austria

            2
            NewbieNewbie
            2

              Nov 03, 2005#6

              Hi Bego,

              Yes, I have checked and it is set to Automatically convert to DOS format. Does this mean that the file will automatically be SAVED as DOS format even though I use the DOS -> Unix conversion on the file?

              I just did an experiment and opend the file, (showed as DOS), converted it to UNIX, saved it and re-opened it and it showed DOS again.

              Dave

              6,686585
              Grand MasterGrand Master
              6,686585

                Nov 03, 2005#7

                I use also the autoconvert to DOS feature all the time and also the Save file as input format option.

                With this settings, a Unix or MAC file is automatically converted to DOS for editing only, but always saved as Unix or MAC according to the format detected during open.

                If "Save file as input format" is not checked, Unix or MAC files are converted automatically to DOS for editing AND are saved as DOS.

                But when you use a conversation manually or within a macro, this automatic file format handlings are disabled and the file is save in the new format indepent of the "Save file as input format", although it is still handled in the buffers of UltraEdit as DOS format.

                So a manual conversation always forces UltraEdit to save the file in this format until it is closed.

                What is still confusing you:

                a) You converted the file to Unix.
                b) You saved the file - it's really stored in Unix.
                c) You close the file.
                d) You open the file - the LFs are automatically converted to CRLF in the buffers.
                e) You look into the file in hex mode and see 0D 0A ????

                Yes, you see 0D 0A, because you see the file buffer content and not what is really saved on your harddisk.

                To see in hex, what is really stored on your harddisk open the file with another hex viewer tool or after c) turn off the autoconvert to DOS feature and then do d) and e).

                So you maybe ask yourself: Why should a Unix or MAC file be converted to a DOS file just for editing and confusing me if a look into it in hex mode?

                It makes sense to convert all line ending variations to DOS just for editing when you copy some lines via clipboard to other programs, which can only work with DOS line terminations.

                Older versions of UltraEdit are also not able to automatically convert a Unix formated clipboard content automatically to current file format on paste from clipboard. Since v11.10 there exists an option in UltraEdit for conversation of line endings to current file format on paste from clipboard. Since v11.10b this function also works for Win9x.
                Best regards from an UC/UE/UES for Windows user from Austria

                344
                MasterMaster
                344

                  Nov 03, 2005#8

                  Hi Dave,

                  Do what Mofi says, he's (almost) always right.
                  Put your Unix file detection option to "detect file type and prompt for change".
                  Now convert your file and save it to - say - c:\unix.txt.
                  Now look at the file with another hex-editor: only LFs inside. Conversion done ok. :D
                  Now open the file again in UE. It should ask you if UE shall concert to DOS (CR/LF) or not. :D

                  Is that what u needed ?

                  rds Bego
                  Normally using all newest english version incl. each hotfix. Win 10 64 bit