以特定的列和特定行从管道分隔的文件 [英] Take specific columns and specific line from a pipe separated file

查看:89
本文介绍了以特定的列和特定行从管道分隔的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .DAT 文件:

  #ID |的firstName | lastName的|性别|生日| creationDate | locationIP | browserUsed
933 |马欣达|佩雷拉|男| 1989年12月3日| 2010-03-17T13:32:10.447 + 0000 | 192.248.2.123 |火狐
1129 |卡门| Lepland |女| 1984年2月18日| 2010-02-28T04:39:58.781 + 0000 | 81.25.252.111 | Internet Explorer中
4194 |胡志明市|景点|男| 1988年10月14日| 2010-03-17T22:46:17.657 + 0000 | 103.10.89.118 | Internet Explorer中
8333 |陈|王|女| 1980年2月2日| 2010-03-15T10:21:43.365 + 0000 | 1.4.16.148 | Internet Explorer中
8698 |陈|刘|女| 1982年5月29日| 2010-02-21T08:44:41.479 + 0000 | 14.103.81.196 |火狐
8853 |阿尔宾| Monteno |男| 1986年4月9日| 2010-03-19T21:52:36.860 + 0000 | 178.209.14.40 | Internet Explorer中
10027 |宁|陈|女| 1982年12月8日| 2010-02-22T17:59:59.221 + 0000 | 1.2.9.86 |火狐

我要带的firstName 的lastName 生日标识特定的行

例如:如果输入的是933,我想提取(由空格分隔):

 马欣达·佩雷拉1989年12月3日


解决方案

这应该这样做:

 #!/ bin / sh的
ID =$ 1
awk的-F| -v ID =$ ID'($ 1 == ID){打印$ 2,$ 3,$ 5}'的infile

使用为:

  $ script.sh 933
马欣达·佩雷拉1989年12月3日

I've got a .dat file:

#id|firstName|lastName|gender|birthday|creationDate|locationIP|browserUsed
933|Mahinda|Perera|male|1989-12-03|2010-03-17T13:32:10.447+0000|192.248.2.123|Firefox
1129|Carmen|Lepland|female|1984-02-18|2010-02-28T04:39:58.781+0000|81.25.252.111|Internet Explorer
4194|Hồ Chí|Do|male|1988-10-14|2010-03-17T22:46:17.657+0000|103.10.89.118|Internet Explorer
8333|Chen|Wang|female|1980-02-02|2010-03-15T10:21:43.365+0000|1.4.16.148|Internet Explorer
8698|Chen|Liu|female|1982-05-29|2010-02-21T08:44:41.479+0000|14.103.81.196|Firefox
8853|Albin|Monteno|male|1986-04-09|2010-03-19T21:52:36.860+0000|178.209.14.40|Internet Explorer
10027|Ning|Chen|female|1982-12-08|2010-02-22T17:59:59.221+0000|1.2.9.86|Firefox

I want to take firstName, lastName and birthday from a specific line by id.

Example: if the input is 933, I want to extract (separated by space):

Mahinda Perera 1989-12-03

解决方案

This should do it:

#!/bin/sh
id="$1"
awk -F '|' -v ID="$id" '($1==ID){print $2, $3, $5}' infile

Use as:

$ script.sh 933
Mahinda Perera 1989-12-03

这篇关于以特定的列和特定行从管道分隔的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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