File Tale Node - Removing ANSI codes

I am using the File Tail node on a log file on edge device. The log file contains ANSI codes for color.

If I use the following i get the log file without the ANSI codes;

tail -f your_log_file.log | sed 's/\x1b\[[0-9;]*m//g'

Any suggestions to have File Tail exclude the ANSI encoding in the text file?

Thanks

You can follow up the File Tail Trigger with either of the following …

  1. A Function Node with this line: payload.result = payload.data.contents.replace(/\x1b\[[0-9;]*m/g, '');
  2. A Run Executable Node with this command: echo '{{{data.contents}}}' | sed 's/\x1b\[[0-9;]*m//g'

The Function Node is probably the better option; depending on the contents of the log file the Run Executable Node could fail in some scenarios, such as single-quotes within the string.

Here’s a screenshot of a debug message generated by the File Tail Trigger and cleaned up by the Function Node. The original content is at data.contents and the sanitized string is at result.

1 Like