如何只获得第三列? [英] How to get only the 3rd column?

查看:40
本文介绍了如何只获得第三列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组@foo,它有像

I have an array @foo which has the entries like

 Database alias                       = SAMPLE1
 Database alias                       = SAMPLE2
 Database alias                       = SAMPLE3

现在我只想要第三列,即

Now i want only the 3rd column i.e

样本 1

样本 2

样本 3

我可以用 awk (awk '{print $3}') 在 shell 中完成,我如何在 perl 中完成?

I can do it in shell with awk (awk '{print $3}') , How do i do it in perl?

推荐答案

awk '{print $3}' < data.txt 

给出 = 符号,你的意思是 $4

gives = signs, you mean $4

然而,在 perl 中,自动拆分数组从零开始,所以它是 3

In perl however, the autosplit array starts at zero so it is 3

perl -lane 'print $F[3]' < data.txt

这篇关于如何只获得第三列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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