【发布时间】:2011-03-07 03:17:24
【问题描述】:
我的脚本看起来像这样
#!/bin/bash
#exampel inputfile is "myfile.txt"
inputfile=$1
basen=`basename $inputfile .txt` # create basename
cat $inputfile |
awk '{print $basen "\t" $3} # this doesn't print "myfile" but the whole content of it.
我想要在上面做的是在 AWK 中打印出之前创建的名为 'basen' 的变量。 但不知何故,它没有达到我希望的效果。
所以例如myfile.txt 包含这些行
foo bar bax
foo qux bar
我希望通过上面的 bash 脚本得到
myfile bax
myfile bar
正确的做法是什么?
【问题讨论】:
-
@tripleee 这个帖子怎么可能是重复的?这是 7 年前发布的,而您建议的帖子是 4 年前发布的。
-
您的常见问题解答。在对重复项进行排序时,问题年龄不是一个重要的考虑因素。另见例如meta.stackoverflow.com/questions/252929/…