Take the 2-minute tour ×
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.

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
add comment

4 Answers

up vote 2 down vote accepted

You can say:

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

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 at 3:05
add comment
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
add comment
 echo $( hasys .. the whole thing )

Just for fun

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.