Score:0

Awk script to filter text output to single line

fr flag

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?

Score:1
cn flag

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}" 
Score:-1
in flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.