0

Sometimes we don't like the standard output of some applications, like apt/pacman. so every time, I have this question: Can I change it to be better or colorize it?

I propose this simple situation below to work on real example:

$ cat standard-app.sh

#!/bin/bash
for i in {1..4}
do
  echo "x = $i"
  // can also use read function or external app
done

$ bash standard-app.sh

x = 1
x = 2
x = 3
x = 4

but, I want to change the output immediately to be like this (before program end):

$ cat fork-app.sh

#!/bin/bash
bash standard-app.sh| ...| ...

$ bash fork-app.sh

value of x is equal to 1
value of x is equal to 2
value of x is equal to 3
value of x is equal to 4

In my opinion, it's required to use tee to output to file and tail to read the end of the file and awk to grep partner or sed to change the output.

Is there another way?

2
  • I don't understand why you don't just pipe the output of standard-app.sh to sed, awk or other suitable tools to process it. The need of tee and tail is unclear to me. Commented Aug 27, 2021 at 9:07
  • pacman supports colours. You just need to enable it in pacman.conf. (apt output also has some colours now, IIRC.)
    – muru
    Commented Aug 27, 2021 at 9:45

1 Answer 1

0
bash standard-app.sh | awk '{printf "value of %s is equal to %s\n", $1, $3}'

If that's not all you need then edit your question to clarify your requirements.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .