Using sed to strip hex x80 through xFF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ljungers
    New Member
    • Dec 2006
    • 114

    Using sed to strip hex x80 through xFF

    have a ASCII file that is messed up. THe problem is that unprintable characters got into this text file. So when printing or using scripts to work with this file I get errors.

    I need to clean up this file removing all hex 80 - FF from this file. Been told that I need to use sed in a script to do this. Have looked for examples but can not find anything dealing with what I need to do.

    Could someone help me with the sed command that I would need to clean this file. I would like to create a new file from the old so that I have the old as a backup just in case.

    Thanks
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    Originally posted by ljungers
    have a ASCII file that is messed up. THe problem is that unprintable characters got into this text file. So when printing or using scripts to work with this file I get errors.

    I need to clean up this file removing all hex 80 - FF from this file. Been told that I need to use sed in a script to do this. Have looked for examples but can not find anything dealing with what I need to do.

    Could someone help me with the sed command that I would need to clean this file. I would like to create a new file from the old so that I have the old as a backup just in case.

    Thanks
    would you want to give a sample of that file?

    Comment

    • ljungers
      New Member
      • Dec 2006
      • 114

      #3
      The file is a regular text file wherre hex 00 - 1F are control characters, hex 20 - 7E are printable characters and hex 7F is DEL chharacter.

      Some how hex (unprintable) characters got into this file (I think that this file was a print file at one time0 like hex characters B0, CA, 80, 83 are one I have found so far.

      I need to read this file and output a files with all hex 80 and above removed from this file so that other scripts can run and use this file without causing errors in the script.

      Thanks for any help you can give me.

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        i can try to help, but please provide a sample. Its easy to strip x80, xFF but i just want to make sure i don't strip useful data.

        Comment

        • Garmo
          New Member
          • Apr 2007
          • 1

          #5
          Originally posted by ghostdog74
          i can try to help, but please provide a sample. Its easy to strip x80, xFF but i just want to make sure i don't strip useful data.
          I need a variation of this command. I'd like to use sed to read a file with no line feeds, and replace a particular sequence with the same sequence preceded by a line feed. This is UNIX. This is what I've tried so far.

          sed 's/ISA/\x'012'ISA/g' filename

          I'm stuck on the syntax for adding a UNIX line feed. Any ideas??

          A typical file would look something like this:

          ISAklsdfsdfgksd fgkjsdfgjdfgsdf gkdISAl;kasdfka sdfkasdfk

          Comment

          • ghostdog74
            Recognized Expert Contributor
            • Apr 2006
            • 511

            #6
            Originally posted by Garmo
            I need a variation of this command. I'd like to use sed to read a file with no line feeds, and replace a particular sequence with the same sequence preceded by a line feed. This is UNIX. This is what I've tried so far.

            sed 's/ISA/\x'012'ISA/g' filename

            I'm stuck on the syntax for adding a UNIX line feed. Any ideas??

            A typical file would look something like this:

            ISAklsdfsdfgksd fgkjsdfgjdfgsdf gkdISAl;kasdfka sdfkasdfk
            for line feed, type ctrl-v then 'm'. NOT shift-6 then 'm'. something like this
            Code:
            sed 's/ISA/^MISA/g' file > file1

            Comment

            Working...