8

When I run the following hasys command with awk , I get output with machines names as the following:

hasys -display|grep Shutdown | awk '{print $1}'
  machine1a
  machine1b

please advice how to print the machines names in one line as the following: example

hasys -display|grep Shutdown | awk '{print $1}'

    machine1a machine1b

what I need to add in my awk syntax so I will able to print the names in one line?

4 Answers 4

12

You can say:

hasys -display | grep Shutdown | awk '{print $1}' ORS=' '
10

The grep with awk is redundant:

 hasys -display | awk '/Shutdown/ { printf "%s ", $1 }'
1
  • 2
    If he wants a newline after the last record, he could do: awk '/Shutdown/ {printf "%s ", $1} END {print ""}'
    – Johnny
    Commented Feb 18, 2014 at 3:05
6
hasys -display | awk '/Shutdown/ {print $1}' | paste -sd ' ' -

Contrary to @devnull's and @jasonwryan's, this one doesn't add a trailing space and terminates the line. paste -sd<sep> - is the generic idiom to join lines into a <sep> separated list.

3
 echo $( hasys .. the whole thing )

Just for fun

You must log in to answer this question.