-1

Console output looks something like below:

User_Group$ls

root
-------------------------------------------------------
copying the above data to a file, it is copied like below:
User_Group$ls�[0m�[01;34mroot�[0m

trying to parse the data and remove "�[0m�[01;34mroot�[0m" I didn't find any match in the ANSII color formats

Could someone suggest some regex operation to remove the above characters and get only "root"

Botje
  • 26,269
  • 3
  • 31
  • 41
sreeja
  • 9
  • 7
  • 1
    Welcome to the stacks. There are some characters not showing properly in the question (showing question marks in black diamond). Try clarifying this. In particular, there is a diamond in between the 0m and the [01, but not in your regex. Also, perhaps add the regex tag to widen the set of readers of your question. – Alan Jun 23 '21 at 10:23
  • 3
    There are a lot of resources in the internet with search keywords "regex ansi color code". Your approach fails because you're trying to match the whole line at once. Instead you need to match and remove each ANDI escape sequence individually. Alsom you need to provide the code you have tried before we can help. – Torben Jun 23 '21 at 10:24
  • I'm trying to replace �[0m�[01;34mroot�[0m with empty string "" – sreeja Jun 23 '21 at 10:57
  • https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream https://stackoverflow.com/questions/6534556/how-to-remove-and-all-of-the-escape-sequences-in-a-file-using-linux-shell-sc https://superuser.com/questions/489151/process-ansi-escape-codes-before-piping – KamilCuk Jun 24 '21 at 11:15

1 Answers1

0

Use regex -> [^A-Za-z0-0]\[[0-9;]*m

[^A-Za-z0-0] -> for special characters

sreeja
  • 9
  • 7