我如何使用从AWK输出另一个命令? [英] How do I use output from awk in another command?
问题描述
所以我需要一个日期转换为不同的格式。随着庆典的管道,我正在从过去的控制台登录的日期,并使用awk拉动相关位出来,像这样:
So I need to convert a date to a different format. With a bash pipeline, I'm taking the date from the last console login, and pulling the relevant bits out with awk, like so:
last $USER | grep console | head -1 | awk '{print $4, $5}'
它输出: 08年8月
($ 4 =八月$ 5 = 08,在此情况下)。
Which outputs: Aug 08
($4=Aug $5=08, in this case.)
现在,我要带8月8日,并把它变成一个日期
命令的格式更改为数字日期。
Now, I want to take 'Aug 08' and put it into a date
command to change the format to a numerical date.
这将是这个样子:
date -j -f %b\ %d Aug\ 08 +%m-%d
输出:08-08
Outputs: 08-08
我的问题是,我如何添加到我的管道,并使用awk的变量$ 4和$ 5,其中8月8日'是在date命令?
The question I have is, how do I add that to my pipeline and use the awk variables $4 and $5 where 'Aug 08' is in that date command?
推荐答案
您只需要使用命令替换:
You just need to use command substitution:
date ... $(last $USER | ... | awk '...') ...
猛砸将评估内部命令/管道 $(...)
和结果放在那里。
这篇关于我如何使用从AWK输出另一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!