Bash:如何在使用cut之前修剪空白 [英] Bash: How to trim whitespace before using cut

查看:83
本文介绍了Bash:如何在使用cut之前修剪空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这样的命令中得到一行输出:

I have a line of output from a command like this:

[]$ <command> | grep "Memory Limit"
Memory Limit:           12345 KB

我正在尝试退出

[]$ <command> | grep "Memory Limit" | cut -d ':' -f2
           12345 KB

试图分开这很棘手。如何修剪空格,以便 cut -d''-f1 返回 12345而不是空格?

Trying to separate this is what's tricky. How can I trim the whitespace so that cut -d ' ' -f1 returns "12345" rather than a blank?

推荐答案

将您的命令放入awk,打印第3列,空格和第4列

Pipe your command to awk, print the 3rd column, a space and the 4th column like this

<command> | awk '{print $3, $4}'

结果为:

12345 KB

<command> | awk '{print $3}'

如果您需要裸机号码。

这篇关于Bash:如何在使用cut之前修剪空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆