Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

You can say:

hasys -display | grep Shutdown | awk '{print $1}' ORS=' '
share|improve this answer

The grep with awk is redundant:

 hasys -display | awk '/Shutdown/ { printf "%s ", $1 }'
share|improve this answer
1  
If he wants a newline after the last record, he could do: awk '/Shutdown/ {printf "%s ", $1} END {print ""}' – Johnny Feb 18 '14 at 3:05
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.

share|improve this answer
 echo $( hasys .. the whole thing )

Just for fun

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.