suhmedoh
suhmedoh

Reputation: 103

is it possible to prepend a character to every line of terminal output, for every command?

Is it possible?

For example, say I want to run the command ll:

My output would look something like this:

josh@zeitgeist ~ ll
total 41148
drwxr-xr-x 42 josh josh     4096 Aug  4 22:52 ./
drwxr-xr-x  4 root root     4096 Jul  9 21:18 ../
-rw-rw-r--  1 josh josh  3523718 Jul 11 00:17 2017-07-11-001710_3840x2160_scrot.png

but I want it to look like this:

josh@zeitgeist ~ ll
XXXtotal 41148
XXXdrwxr-xr-x 42 josh josh     4096 Aug  4 22:52 ./
XXXdrwxr-xr-x  4 root root     4096 Jul  9 21:18 ../
XXX-rw-rw-r--  1 josh josh  3523718 Jul 11 00:17 2017-07-11-XXX001710_3840x2160_scrot.png

I already know about using PS1='XXX' to change the prompt; is there a way to change every line of the output that gets displayed, specifically in the terminal(not changing the output and putting it in a file)?

I would like to do this to have a unified line of characters going down the left side of my terminal.

Upvotes: 1

Views: 397

Answers (4)

Walter A
Walter A

Reputation: 20022

Prepend XXXto all lines including empty lines.

ll | sed 's/^/XXX/'

Edit: After changing your PS1 you can invoke the solution for all commands using

bash | sed 's/^/XXX/'

Upvotes: 1

James Brown
James Brown

Reputation: 37424

Using awk:

$ ll|awk '$0="XXX"$0'

Upvotes: 0

whoan
whoan

Reputation: 8531

You can easily do it with sed:

ll | sed 's/./XXX&/'

Upvotes: 4

I0_ol
I0_ol

Reputation: 1109

You could do something like this I suppose:

while read; do echo "xxx $REPLY"; done < <(ls -l)

Not really sure what the purpose of this would be though.

Upvotes: 0

Related Questions