Tapatalk

Delete line if does not start with a specified character or word

Delete line if does not start with a specified character or word

2
NewbieNewbie
2

    Sep 09, 2005#1

    I need to delete all lines in a text file that doesn't start with "@".

    For example

    FFFFFF
    @GGG
    AAAAA
    @BBBB

    should result:

    @GGG
    @BBBB

    i'm trying with IfnotFound but I'm getting errors.
    any help? thanks

    206
    MasterMaster
    206

      Sep 09, 2005#2

      Do a regular Search/Replace All
      Regular Expressions checked (Unix-style)

      Find What: ^[^@].*\p
      Replace With: nothing
      Software For Metalworking
      http://closetolerancesoftware.com

      2
      NewbieNewbie
      2

        Sep 09, 2005#3

        I've edited the next macro but it's not working

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOn
        Top
        Find RegExp "^[^@].*\p"
        Replace All ""

        Is this correct?

        Edit: RegExp parameter was missing.

        5
        NewbieNewbie
        5

          Nov 17, 2008#4

          Using this thread to modify my own macros I've come up with the problem..

          When I search for ^[^@].*\p in a file containing the lines...

          Code: Select all

          FFFFFF
          @GGG
          AAAAA
          @BBBB 
          it works properly showing me the lines...

          Code: Select all

          FFFFFF
          AAAAA
          But when I use it for my own purposes I try searching for ^[^http].*\p in the lines....

          Code: Select all

          http://www.www.com/
          http://www.www.com
          ftp.www.com
          http://www.ftp.com
          And I get an UltraEdit popup saying...

          Code: Select all

          Search string '^[^http].*\p' not found!
          I am sure to check Unix Regular Expressions so what fundamental gap in knowledge am I missing here?

          236
          MasterMaster
          236

            Nov 17, 2008#5

            [^http] means "Match any one character except h, t or p". So your regex should match ftp.www.com (and it does for me in v14.20.0.1035). However, it will also match a line like "this line starts with a t".

            What you want to do requires Perl regular expressions.

            ^\s*(?!http).*\r\n

            will match a (DOS file) line that doesn't start with "http" (leading whitespace ignored).

            5
            NewbieNewbie
            5

              Nov 17, 2008#6

              Ahh, beautiful. Thanks pietzcker!

              I spent much of the night reading how to do it with unix expressions. I'll have to read up on perl next.

              Some keywords to help people find it: find word at start of the line cut it select line out paste it into new file txt

              And the description of what it does...

              Searches for lines that don't start with desired words (http in this case), selects those lines, cuts them out and pastes them into a newly opened file so you can review what was removed from the original file.

              Show Cancel dialog for this macro: unchecked
              Continue if search string not found: checked

              InsertMode
              ColumnModeOff
              HexOff
              PerlReOn
              Top
              Clipboard 9
              ClearClipboard
              Loop 0
              Find RegExp "^\s*(?!http).*\r\n"
              IfFound
              CutAppend
              Else
              ExitLoop
              EndIf
              EndLoop
              NewFile
              Paste
              ClearClipboard
              Clipboard 0
              Top