1

So to put it less confusing:

I run a command which prints some formatted values in the bash e.g.:

  • NodeID (lot of whitespace) Heap_size (again) Time

And when i try to save the output with Name:~$ script > file.txt, the output is:

ESC[93mnode_s1aESC[0m^MESC[25C1.0g

Expected output:

node_s1a            1.0g       ...
node_s2aaaaa        2.0g       ...

Is there a way to save raw output with the formatting into a text file ?

Jan
  • 50
  • 5
  • 3
    That is a bug with the program producing the output, as it is writing terminal control characters when it is not writing to a terminal. Perhaps the command you are using has an option to suppress that behavior. – William Pursell Aug 03 '20 at 15:35
  • 1
    Possible duplicate of https://stackoverflow.com/questions/17998978/removing-colors-from-output – tripleee Aug 03 '20 at 15:41
  • Thanks both, one is a cause and the second is at least partly solution, so i think this topic can be closed. – Jan Aug 04 '20 at 10:54

1 Answers1

-2

You can use the printf command which is like the printf function in C or Java.

printf "%-20s%s" Name:~$ script >> test.txt

I'm assuming Name:~$ and script are variables because I've never seen them before.

person
  • 313
  • 1
  • 10
  • 1
    `Name:~$`is the Bash prompt and `script` is the name of the script they are running. Probably stay away from topics you are clearly not familiar with. – tripleee Aug 03 '20 at 15:42