A
A
Astral1004982020-12-09 21:54:51
linux
Astral100498, 2020-12-09 21:54:51

How to completely remove control characters from a file?

Good afternoon. I write the result of the program execution to a file with the following command sudo trafshow -i enp0s3 > file.txt

The output is the following:

[?1049h [22;0;0t [1;24r (B [m [4l [?7h [39;49m [39;49m (B [m [H [2JSource [1;27HDestination [1;53HProtocol Size [75GCPS
[2d (0 [0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq (B [23;1H (0 [0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq (B [24;1H (0 [0m (Benp0s3 [24;27H0 Flows [24;53HTotal: 0 [75G0 [HSource [20X [1;27HDestination [15X [1;53HProtocol Size CPS [K
[2d (0 [0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq (B [3;1H (0 [0m (B [K [4d [K [5d [K [6d [K [7d [K [8d [K [9d [K [10d [K [11d [K [12d [K [13d [K [14d [K [15d [K [16d [K [17d [K [18d [K [19d [K [20d [K [21d [K [22d [K [24;80H [HSource [20X [1;27HDestination [15X [1;53HProtocol Size CPS [K
[2d (0 [0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq (B [3;1H (0 [0m (B [K [4d [K [5d [K [6d [K [7d [K [8d [K [9d [K [10d [K [11d [K [12d [K [13d [K [14d [K [15d [K [16d [K [17d [K [18d [K [19d [K [20d [K [21d [K [22d [K [24;80H [HSource [20X [1;27HDestination [15X [1;53HProtocol Size CPS [K
[2d (0...........................


Found on the Internet how to convert to a readable form, the following command
tr -s "[\027]" "\n" < /1.txt |\
sed -n '/Source/,${
     s/\(^.*\).$/\1/
     /^.*qqqqqqqq.*$/d
     s/^[a-zA-Z]\(.*\)/\1/
     s/^[0-9][a-zA-Z]\(.*\)/\1/
     / [ ]*$/s/ [ ]*$//
     /^.......................*/p
     }' > /2.txt


I get the following
1;53H Protocol Size CPS
0;7m 192.168.0.1,domain 10.0.2.15,53512 udp 374
31m 10.0.2.15,53512 192.168.0.1,domain udp 140
1;53H Protocol Size CPS
0;7m 13.33.240.3,https the tcp 9K 2.15,52224
31m 10.0.2.15,52224 13.33.243.3, https 1510 the tcp
192.168.0.1, domain 10.0.2.15,37755 udp 804
10.0.2.15,56486 34.107.221.82, http tcp 432
10.0.2.15,56484 34.107.221.82 ,http tcp 427
192.168.0.1,domain 10.0.2.15,40416 u1;53HProtocol Size CPS 0
;7m 192.168.0.1, domain
10.0.2.15,53512 Protocol Size CPS 0;7m

13.33.243.3, https 10.0.2.15.52224 TCP 9k
31m 10.0.2.15.52224 13.33.243.3, https tcp 1510
192.168.0.1, Domain 10.0.2.15.37755 UDP 804
10.0.2.15.56486 34.107.21.82, HTTP TCP 432, HTTP TCP
43 .2.15,56484 34.107.221.82, http tcp 427
192.168.0.1, domain 10.0.2.15,40416 udp 380
192.168.0.1, domain 10.0.2.15,58929 udp 380dp 380
192.168.0.1, domain 10.0.2.15,58929 udp 380


But for some reason did not completely remove the characters. I highlighted in bold.
Help fix this. Not very strong on Linux

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-12-10
@dtmse

sudo iftop -PtNn -i enp3s0 > file.txt
or netflow sensor + netflow collector if you need to collect traffic data on an ongoing basis (for example, fprobe + nfdump)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question