[英]Print awk output on the same line
How do I print awk output on the same line. 如何在同一行上打印awk输出。
I am using this to print the resolution of my monitor: 我正在使用它来打印显示器的分辨率:
$ xrandr | awk '/\*/{print $1}'
When I connect a second monitor I get output on two lines, 当我连接第二台显示器时,我得到两行输出,
$ xrandr | awk '/\*/{print $1}'
1920x1200
1600x1050
I would like to have the output on the same line. 我想在同一行上输出。 So it will look like this:
所以它看起来像这样:
Monitor sizes: 1920x1200 1600x1050
How would I do this the simplest way? 我将如何以最简单的方式执行此操作?
You can append xargs
to your command, eg 您可以将
xargs
附加到命令中,例如
$ xrandr | awk '/\*/{print $1}' | xargs
Here is alternative command using grep
and xargs
: 这是使用
grep
和xargs
替代命令:
$ grep -o '[0-9]\+x[0-9]\+' <(xrandr) | xargs
1440x878 2880x1800 1440x900 2560x1600 2048x1280 1024x768 800x600 640x480 1680x1050 1280x800 1440x878
Or using echo
: 或使用
echo
:
$ echo Monitor sizes: $(grep -o '[0-9]\+x[0-9]\+' <(xrandr))
Monitor sizes: 1440x878 2880x1800
I have found this solution that is similar to what anubhava posted. 我发现此解决方案类似于anubhava发布的解决方案。
$ xrandr | awk '/\*/{printf $1" "}'
1920x1200 1600x1050
It is nice to know paste
: 很高兴知道
paste
:
xrandr | awk '/\*/{print $1}' | paste - -
You can also iuse echo
: 您也可以使用
echo
:
echo $(xrandr | awk '/\*/ {print $1}' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.