shantanuo
shantanuo

Reputation: 32306

Output on a single line

The following code is working as expected. But I can not format the output. It will print something like this:

mysql
test
someDB

I want the output on a single line

mysql test someDB

I tried using sed in the script but it did not work.

#!/bin/sh
for dbName in `mysqlshow -uroot -pPassWord | awk '{print $2}'`
do
echo "$dbName" | egrep -v 'Databases|information_schema';
done

Upvotes: 2

Views: 11565

Answers (4)

ghostdog74
ghostdog74

Reputation: 342303

you can use tr to get your output to one line

<output from somewhere> | tr "\n" " "

Upvotes: 6

Dennis Williamson
Dennis Williamson

Reputation: 359905

To do a variation combining naumcho's and rsp's answers that will work for small numbers of results:

echo $(mysqlshow -uroot -pPassWord | awk '{print $2}' | egrep -v 'Databases|information_schema')

Upvotes: 1

naumcho
naumcho

Reputation: 19881

whenever you want to combine all lines of output into one you can also use xargs:

e.g.

find 
.
./zxcv
./fdsa
./treww
./asdf
./ewr

becomes:

find |xargs echo
. ./zxcv ./fdsa ./treww ./asdf ./ewr

Upvotes: 12

rsp
rsp

Reputation: 23373

The newline is generated by the echo command most likely, the following should do the same without the newlines (not tested)

mysqlshow -uroot -pPassWord | awk '{print $2}' | egrep -v 'Databases|information_schema'

and has the added bonus of spawning just 1 grep instead of 3 grep processes.

Upvotes: 1

Related Questions