Search code examples
bashreplaceoutputlines

Replace text in multiple lines


i try to replace some text parts of my bash output. My bash output looks like:

vserver            policyname  clientmatch  rorule rwrule superuser
------------------ ----------- ------------ ------ ------ ---------
Vserver1           Volume1     Host1        sys    never  sys
Vserver2           Volume2     Host2        sys    never  sys
Vserver3           Volume3     Host3        sys    none   never
Vserver4           Volume4     Host4        sys    never  sys
Vserver5           Volume5     Host5        sys    sys    sys

I want to replace:

sys with true
none with false
never with false

How I can do that? My output is showing me all lines at once and this try doesn't work for me:

RED_TEXT=$(tput setaf 1)
GREEN_TEXT=$(tput setaf 2)
BOLD_TEXT=$(tput bold)
RESET_TEXT=$(tput sgr0)

true=${GREEN_TEXT}true${RESET_TEXT}
false=${RED_TEXT}false${RESET_TEXT}

echo "$OUTPUT" | sed "s/sys/${true}/g" | sed "s/never/${false}/g" | sed "s/none/${false}/g"

What I am doing wrong?

Thank you and best regards!


Solution

  • You can try this may be help you?

    echo **-n** "$OUTPUT" | sed "s/sys/${true}/g" | sed "s/never/${false}/g" | sed "s/none/${false}/g"
    

    Or

    echo **-n** "$OUTPUT" | sed -e 's/sys/${true}/g' | sed -e 's/none/${false}/g' | sed -e 's/never/${false}/g'