0

I am trying to write a bash script

Node.js code outputs to terminal and logs to file as well

I need to remove everything between '[Progress]' and this emoji '' while writing to file but should print in terminal.

Works fine on mac if i open with an vscode or similar editor but on an ubuntu machine on vim it hows everything as if nothing changed all Progress and color codes are still there.

for the emoji I tried with an code this emoji I am using is \ud83d

here is my code

LOG_FILE='output.log'
node inddex.js 2>&1 \
    | tee /dev/tty \
    | sed -e $'s,\[Progress\].*,,g' -e $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' \
    > $LOG_FILE

My node output is something like (for multiple single line)

[2K[1G[Progress]: Processing Records ...[2K[1G[Progress]: Processed Records: [33m816[0m [2K[1G[Progress]: Processed Records: [33m1725[0m [2K[1G[Progress]: Processed Records: [33m2774[0m [2K[1G[Progress]: Processed Records: [33m4041[0m [2K[1G[Progress]: Processed Records: [33m5207[0m [2K[1G[Progress]: Processed Records: [33m6557[0m [2K[1G[Progress]: Processed Records: [33m8590[0m [2K[1G[Progress]: Processed Records: [33m9811[0m [2K[1G  Time taken to process [33m10000[0m records = [36m8.54 sec[0m

for above line I only need to process this to output file and display everything on terminal

  Time taken to process 10000 records = 8.54 sec
joyBlanks
  • 6,419
  • 1
  • 22
  • 47
  • Using `$''` is strange with `sed`. `sed` can itself interpret hex sequences. – KamilCuk Mar 11 '19 at 19:43
  • @KamilCuk No, not universally; that depends entirely on the `sed` dialect. – tripleee Mar 11 '19 at 19:47
  • 1
    @joyBlanks try substituting `` for `\xf0\x9f\x9a\x80` hexadecimal characters. – KamilCuk Mar 11 '19 at 19:50
  • It seems in Ubuntu it simply ignores `sed -e $'s,\[Progress.*\xf0\x9f\x9a\x80,\xf0\x9f\x9a\x80,g' -e $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' \` – joyBlanks Mar 11 '19 at 19:59
  • I tried #!/bin/bash and #!/bin/sh with sh script.sh and ./script.sh same thing. In mac it runs fine in Ubuntu the file has everything not removes my progress lines – joyBlanks Mar 11 '19 at 20:00
  • ok one more thing i tried cat output.log and I didn't see the progress lines. the ansi colors were there since cat outputs to the terminal but how come Progress lines are missing there? I much dont care about ansi color codes but I need to get rid of the progress lines – joyBlanks Mar 11 '19 at 20:06

0 Answers0