Home > Net >  piping echo and cat not works
piping echo and cat not works

Time:12-10

I'm coding script which installing firmware for server.
have stuck in args for output versions from XML files in terminal.

echo "BROADCOM NIC Version : " | cat firmware-nic-broadcom-*/CP*.xml | grep "<Version>" | uniq | sed 's/[^0-9,.]//g'

I want to output "BROADCOM NIC Version : 20.19.31"
But it just show "20.19.31"

how to fix this?

CodePudding user response:

Here's one simple way to do it:

echo -n "BROADCOM NIC Version : " ; cat firmware-nic-broadcom-*/CP*.xml | grep "<Version>" | uniq | sed 's/[^0-9,.]//g'
     ^^ Add                       ^ Change

The -n flag says echo with no new line, and changing the | to a ; means that it always outputs directly rather than getting lost in the piping.

CodePudding user response:

You can declare VERSION variable first.

VERSION=$(cat firmware-nic-broadcom-*/CP*.xml | grep "<Version>" | uniq | sed 's/[^0-9,.]//g')
echo "BROADCOM NIC Version : ${VERSION}"
  • Related