Search and Replace Printer codes in text file

  • Jeffery Smith

    Jeffery Smith - 2013-06-06

    I've got a program that generates a text file, but put printer ESC codes in the file such as

    {non-printable ESC character}&l5.62C{non-printable ESC character}(s17H

    Every utility I've tried won't accept the characters in a search and replace operation. By far, the SFK looks like the most feature full utility that I've looked at. The problem is I can't include the non-printing characters in a batch file as they act as a CR. I'm hoping there is a way in SFK to either search and replace the string including non-printable characters or a way to run a first pass stripping out the non-printable characters and a second pass doing the ASCII search and replace. Any ideas?

    If this utility doesn't have the capabilities, can you think of another utility that could do this?



  • stahlworks

    stahlworks - 2013-06-07

    "sfk ascii" tells that ESC has the hexadecimal code 0x1B.
    To replace something in plain text, use the sfk filter command.
    To allow replacement of non printable characters, use option -spat
    for "slash patterns" and type ESC like "\x1B", meaning "a character
    with hex code 1B". Example:

    sfk filter in.txt -spat -rep "_\x1B&l5.62C\x1B(s17H__" +tofile out.txt

    will strip a sequence with ESC chars from in.txt, writing the result to out.txt.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks