0

I have a script that is giving me an output like this:

ruby-devel is needed by software1
tcl is needed by software 2
python3 is needed by software 3
ocaml is needed by software 1

I'm new to awk but was trying to script it to get the first word, and put it in a single line (can use sed or the best way to actually do this, I couldn't do it) to be able to build an output like this:

You need to get: ruby-devel tcl python3 ocaml
Run: yum install ruby-devel tcl python3 ocaml

Any help on how to do that?

Emersonjr
  • 11
  • 2

2 Answers2

1

Assuming you're using bash, something like this?

WORDS=$( your_script | awk '{printf("%s ",$1);}' )

printf 'You need to get: %s\n'  "${WORDS}"
printf 'Run: yum install %s'  "${WORDS}" 
Phill W.
  • 1,479
  • 7
  • 7
-1

awk

awk '{if ($1~/ruby|tcl|python3|ocaml/) $1="ruby-devel tcl python3 ocaml" } END { print "You need to get:", $1, "\nRun: dnf install", $1 }' $file
HatLess
  • 130
  • 6