awk从atq检索第一个字段报告 [英]awk to retrieve the first field report from atq

一位学习者分享了使用awk命令从数据流中提取第一字段的经历,虽然最初尝试未达预期,但发现通过简单调整即可实现目标。文章探讨了如何正确使用awk的print命令,并解释了单引号在避免shell参数扩展中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am learning awk to advance my skills and tried

我正在学习awk以提升我的技能并尝试过

$ atq | awk "{print $1}" 
28  Wed Oct 31 10:23:00 2018
27  Tue Oct 30 21:20:00 2018
25  Tue Oct 30 21:19:00 2018
29  Wed Oct 31 10:42:00 2018
26  Tue Oct 30 21:20:00 2018
20  Tue Oct 30 18:25:00 2018
30  Wed Oct 31 10:59:00 2018
32  Wed Oct 31 21:03:00 2018
23  Tue Oct 30 18:28:00 2018
31  Wed Oct 31 13:58:00 2018
19  Tue Oct 30 15:43:00 2018
21  Tue Oct 30 18:27:00 2018
It did not work as I expected, but it's relatively easy to work small programs together

它没有像我预期的那样工作,但是将小程序一起工作相对容易

$ atq | cut -f 1
28
27
25
29
26
20
30
32
23
31
19
21
How could I retrieve the first field using awk?

我怎么能用awk检索第一个字段?

1 个解决方案
#1
7  

Try the below,

试试下面的,

atq | awk '{print $1}'
The single quotes stops the shell from expanding $1 to the shell's first positional parameter.

单引号阻止shell将$ 1扩展到shell的第一个位置参数。

 

本文转载自

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值