Removal of string in script

Asked

Viewed 36 times

0

To edit this file and remove any incidence of [[*m as I edit sed? The incidences are marked in bold.

sed’s/ [[*m//g' file

The backup routine is still running on the server!

The backup process began at 15:19:28 EDT and is currently on account **^[[1;33m0^[[0;00m** out of **^[[1;33m5** **^[[97m(0%)^[[0;00m**

Time since backups started: 00:00:05

Currently there are **^[[1;33m0^[[0;00m** accounts being excluded from backups.
To watch the log, use this command: **^[[97m**tail -f /usr/local/cpanel/logs/cpbackup/1497899968.log**^[[0;00m**

To check for backup duration history run: ^[[1;32m bash <(curl -ks scriptorigem) ^[[0;00m

2 answers

2

Apparently, the occurrences you want to filter are ANSI exhaust sequences.

In this case, you can use a utility called ansifilter to solve your problem:

$ ansifilter -i entrada.txt -o saida.txt

Alternatively you can use the utility sed to remove the escape sequences \x1b:

$ sed 's/\x1b//g' entrada.txt

1

with a sed-only command you can remove all escape sequences from the terminal as follows:

sed 's/\^\[\[[^m]\+m//g' <seu_arquivo>

in sed, characters that have meaning in Regular Expressions need to be escaped (^, [ and +).

  • It seems that these characters shown in the output have to do with escape, as Lacobus' reply makes very clear.

  • 1

    They are in fact ANSI escape sequences for the terminals as it was by @Lacobus. I would bet that the backup system that OP quoted expected this output to be directed to a terminal (STDOUT or STDERR) and not a file.

  • it is. My experience is that it ends up not being filtered by the text it displays, the text that marries with its regex, but I’m not sure

Browser other questions tagged

You are not signed in. Login or sign up in order to post.