Home > database >  handle self-deleting console outputs in unix\shell\bash
handle self-deleting console outputs in unix\shell\bash

Time:02-28

I want to download a huge file from s3 to a server so I'm using nohup. Problem is, the process outputs "self-updating reports", which are cool in the terminal but are horrible when written to a file as a single long line.

my questions are:

  1. how should I handle this output to avoid a 84MB text file of just one line?
  2. given that I have such a file, how can I read it's "bottom line" effectively?

thanks!

CodePudding user response:

The "self-updating" text is just a carriage return character, which when printed to the terminal moves the cursor back to the beginning of line, allowing you to overwrite any previous text on the line.

To remove everything up through the last carriage return character,

awk '{ sub(/.*\r/, ""); }1' file

or the same with any regex tool (sed 's/.*\r//' file would work if your sed recognizes the nonstandard \r escape).

Some tools have an option to turn off progress updates; if you are using the standard aws s3 cp, try adding the option --no-progress.

  • Related