为什么不是这个awk命令工作 [英] Why isn't this awk command working
本文介绍了为什么不是这个awk命令工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,问题是:
显示所有示出只的数量和产品名的文件中的线,以该顺序,用awk。产品名称为第一场和数量是第二场。数据文件为库存
Display all of the lines in the file showing only the quantity and product name, in that order, using awk. Product name is the first field and quantity is the second field. The data file is "inventory"
内容盘点:
Strawberry Jam,300,4
Raspberry Jam,1216,7
Blueberry Jam,96,195
Strawberry Compote,49,621
Raspberry Compote,1937,624
Blueberry Compote,200,625
Frozen Strawberries,130,1941
Straw Hats,16,2047
我的命令是
awk '$2 $1' inventory
这应该工作的权利?我也试着像
That should work right? I also tried like
awk '{print $2 $1}' inventory
awk '$2, $1' inventory
和了很多的变化,但没有工作!有人可以帮助找出为何?
and a lot of variations of that, but none works! Can anyone help figure out why?
推荐答案
这是一个 CSV
的(逗号分隔值)的文件,在字段分隔符
需要被指定为,
使用 -F
选项。
That is a csv
(comma seperated values) file so the field separator
needs to be specified as ,
using the -F
option.
$ awk -F, '{print $2,$1}' inventory
300 Strawberry Jam
1216 Raspberry Jam
96 Blueberry Jam
49 Strawberry Compote
1937 Raspberry Compote
200 Blueberry Compote
130 Frozen Strawberries
16 Straw Hats
这篇关于为什么不是这个awk命令工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文