显示以1或0结尾的所有行以及行中最后一个字符的第3行中的1

时间:2013-10-01 19:21:40

标签: linux unix grep

我尝试显示以1或0结尾的所有行,并使用grep显示行中最后一个字符的第3行中的1。

01 m motzart        amadeous        25 2nd 94233
02 m guthrie        woody           23 2nd 94223
03 f simone         nina            27 2nd 94112
04 m lennon         john            29 2nd 94221
05 f harris         emmylou         20 2nd 94222
06 m marley         bob             22 2nd 94112
07 f marley         rita            26 2nd 94212
08 f warwick        dione           26 2nd 94222
09 m prine          john            35 3rd 94321
10 m franti         michael         34 3rd 94112
11 f black          mary            21 2nd 94221
12 m dylan          bob             37 3rd 94311
13 f baez           joan            36 3rd 94311
14 m richards       keith           42 4th 94112
15 m jagger         mick            41 4th 95115
16 m mcdonald       countryjoe      46 4th 94543
17 f chapman        tracy           43 4th 94211
18 m springstein    bruce           45 4th 94323
19 f mitchell       joni            40 4th 94444
20 f walker         alice           37 3rd 94332
21 f oliver         mary            47 4th 94114
22 m kotzwinkle     william         44 4th 94433
23 f kate           wilhelm         73 7th 94778
24 m heinlein       robert          74 7th 94765
25 m asimov         isaac           75 7th 94777
26 m moose          bullwinkle      16 1st 94111
27 m squirrel       rocketJ         17 1st 94122
28 f fenwich        nell            13 1st 94221
29 m peobody        mr              18 1st 94222
30 m longlastname   longfirstname   11 1st 94313
31 m leaves         t               22 2nd 94223
32 m hanh           thichNhat       26 2nd 94115
33 m chomsky        noam            34 3rd 94116
34 m morrison       norman          71 7th 94771
35 f anthony        susanB          48 4th 94321
36 m kropotkin      peter           49 4th 94115
37 m gandhi         mohatmas        53 5th 95123
38 f tubman         harriet         50 5th 95555
39 m king           martinLuther    52 5th 95112
40 m chavez         cesar           57 5th 95112
41 m douglas        frederick       66 6th 94666
42 f goldman        emma            64 6th 94611
43 f mandela        nelson          60 6th 96543
44 f parks          rosa            72 7th 94777
45 m russell        bertrand        55 5th 94113
46 f lovelace       ada             56 5th 95123
47 m darwin         charles         59 5th 95123
48 m galileo        galileli        58 5th 95113
49 m einstein       albert          54 5th 94113

这是文件

2 个答案:

答案 0 :(得分:2)

这应该这样做:

grep '1.[10]$' filename

我创建了以下测试输入文件:

198273789120
123981298371
239817239111
123981239871
192873698127

并运行上面的grep命令,得到了这个输出:

198273789120
239817239111

打印的两行以0或1结尾,并以1作为行的倒数第3个字符。

答案 1 :(得分:0)

你可以试试这个

egrep -e '1.(1|0)$' your_file

返回以1或1结尾的任何行,并在第3位到最后位置处有1。