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

Regular Expression to Strip lines of "]"

Expand Messages
  • lm_hamilton
    I have a file that has hundreds of lines of several hundred right square brackets ] . I cannot control how I receive this file, but I have to clean it up. I
    Message 1 of 4 , May 25, 2005
    • 0 Attachment
      I have a file that has hundreds of lines of several hundred right
      square brackets "]".

      I cannot control how I receive this file, but I have to clean it up. I
      can get it so that there is the junk at the end, and then have to
      manually delete it.

      I have tried these perl one liners to no avail, it just spits out a
      copy of the file.

      perl -p -e 's/\x5D+//g' file.ddf > file.txt
      perl -p -e 's/\]+//g' file.ddf > file.txt
      perl -p -e 's/\\]+//g' file.ddf > file.txt
      perl -p -e 's/]+//g' file.ddf > file.txt
      perl -p -e 's/]+\n//g' file.ddf > file.txt
      perl -p -e 's/]*\n//g' file.ddf > file.txt
      perl -p -e 's/\x5D*\n//g' file.ddf > file.txt
      perl -pe 's/]*\n//g' file.ddf > file.txt
      perl -pe 's/\x5D*\n//g' file.ddf > file.txt
      perl -pe 's/[\x5D*\n]//g' file.ddf > file.txt

      What I want to do is just strip out the entire line of "]" and the
      line break.

      It is a piece of cake in NoteTab, but I need to do it in Perl.

      Any ideas or pointers on what I am missing are greatly appreciated!

      THANKS!

      Larry Hamilton
    • lm_hamilton
      After much Googling and further trial and error, I found it. I thought I had tried this before and it did not work, but I was mistaken. Here it is:
      Message 2 of 4 , May 25, 2005
      • 0 Attachment
        After much Googling and further trial and error, I found it.

        I thought I had tried this before and it did not work, but I was mistaken.

        Here it is:

        tr/\x5D+\n//d;

        The transliteration operator tr also can use y.

        Larry

        --- In ntb-scripts@yahoogroups.com, "lm_hamilton" <lmh@h...> wrote:
        > I have a file that has hundreds of lines of several hundred right
        > square brackets "]".
        >
        > I cannot control how I receive this file, but I have to clean it up. I
        > can get it so that there is the junk at the end, and then have to
        > manually delete it.
        >
        > I have tried these perl one liners to no avail, it just spits out a
        > copy of the file.
        >
        > perl -p -e 's/\x5D+//g' file.ddf > file.txt
        > perl -p -e 's/\]+//g' file.ddf > file.txt
        > perl -p -e 's/\\]+//g' file.ddf > file.txt
        > perl -p -e 's/]+//g' file.ddf > file.txt
        > perl -p -e 's/]+\n//g' file.ddf > file.txt
        > perl -p -e 's/]*\n//g' file.ddf > file.txt
        > perl -p -e 's/\x5D*\n//g' file.ddf > file.txt
        > perl -pe 's/]*\n//g' file.ddf > file.txt
        > perl -pe 's/\x5D*\n//g' file.ddf > file.txt
        > perl -pe 's/[\x5D*\n]//g' file.ddf > file.txt
        >
        > What I want to do is just strip out the entire line of "]" and the
        > line break.
        >
        > It is a piece of cake in NoteTab, but I need to do it in Perl.
        >
        > Any ideas or pointers on what I am missing are greatly appreciated!
        >
        > THANKS!
        >
        > Larry Hamilton
      • Alan C
        perl -pe s/ ]+ n//g file.txt That did it here on Linux. Sometimes Win needs double quotes if trying it on Windows.
        Message 3 of 4 , May 25, 2005
        • 0 Attachment
          perl -pe 's/\]+\n//g' < file.ddf > file.txt

          That did it here on Linux. Sometimes Win needs double quotes if trying
          it on Windows.

          http://www.perl.com/pub/a/2004/08/09/commandline.html?page=2

          scroll down near bottom, entitled "In-place editing"

          tr can do lots. I never know when to use substitution operator (regex)
          versus tr transliteration operator.

          Alan.

          lm_hamilton wrote:

          >After much Googling and further trial and error, I found it.
          >
          >I thought I had tried this before and it did not work, but I was mistaken.
          >
          >Here it is:
          >
          >tr/\x5D+\n//d;
          >
          >The transliteration operator tr also can use y.
          >
          >Larry
          >
          >--- In ntb-scripts@yahoogroups.com, "lm_hamilton" <lmh@h...> wrote:
          >
          >
          >>I have a file that has hundreds of lines of several hundred right
          >>square brackets "]".
          >>
          >>I cannot control how I receive this file, but I have to clean it up. I
          >>can get it so that there is the junk at the end, and then have to
          >>manually delete it.
          >>
          >>I have tried these perl one liners to no avail, it just spits out a
          >>copy of the file.
          >>
          >>perl -p -e 's/\x5D+//g' file.ddf > file.txt
          >>perl -p -e 's/\]+//g' file.ddf > file.txt
          >>perl -p -e 's/\\]+//g' file.ddf > file.txt
          >>perl -p -e 's/]+//g' file.ddf > file.txt
          >>perl -p -e 's/]+\n//g' file.ddf > file.txt
          >>perl -p -e 's/]*\n//g' file.ddf > file.txt
          >>perl -p -e 's/\x5D*\n//g' file.ddf > file.txt
          >>perl -pe 's/]*\n//g' file.ddf > file.txt
          >>perl -pe 's/\x5D*\n//g' file.ddf > file.txt
          >>perl -pe 's/[\x5D*\n]//g' file.ddf > file.txt
          >>
          >>What I want to do is just strip out the entire line of "]" and the
          >>line break.
          >>
          >>It is a piece of cake in NoteTab, but I need to do it in Perl.
          >>
          >>Any ideas or pointers on what I am missing are greatly appreciated!
          >>
          >>THANKS!
          >>
          >>Larry Hamilton
          >>
          >>
          >
          >
          >
          >
          >
          >ntb-scripts-unsubscribe@yahoogroups.com
          >
          >
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
        • Larry Hamilton
          Thanks Alan. I ll have to try this one and see how it does. Larry Hamilton Kairos Computer Solutions http://www.kairoscomputers.com/ Sales Affiliate for
          Message 4 of 4 , May 26, 2005
          • 0 Attachment
            Thanks Alan.

            I'll have to try this one and see how it does.

            Larry Hamilton
            Kairos Computer Solutions
            http://www.kairoscomputers.com/
            Sales Affiliate for Grisoft Anti-Virus

            Alan C wrote:
            > perl -pe 's/\]+\n//g' < file.ddf > file.txt
            >
            > That did it here on Linux. Sometimes Win needs double quotes if trying
            > it on Windows.
            >
            > http://www.perl.com/pub/a/2004/08/09/commandline.html?page=2
            >
            > scroll down near bottom, entitled "In-place editing"
            >
            > tr can do lots. I never know when to use substitution operator (regex)
            > versus tr transliteration operator.
            >
            > Alan.
          Your message has been successfully submitted and would be delivered to recipients shortly.