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?

2 Answers 2

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}" 
-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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.