开发者

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 -开发者_如何学JAVAuroot -pPassWord | awk '{print $2}'`
do
echo "$dbName" | egrep -v 'Databases|information_schema';
done


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


you can use tr to get your output to one line

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


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')


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜