您的位置:首页 > 其它

把一个文件的偶数行,或者奇数行提取出来

2014-05-07 09:03 253 查看
>>第一种方法<<

sed -n '1~2p'

sed -n '2~2p'

info sed

`FIRST~STEP'

This GNU extension matches every STEPth line starting with line

FIRST. In particular, lines will be selected when there exists a

non-negative N such that the current line-number equals FIRST + (N

* STEP). Thus, to select the odd-numbered lines, one would use

`1~2'
'FIRST~STEPp'
意为提取行是从FIRST处开始,每隔(步长)为STEP

>>第二种方法<<

awk 'NR%2==1' file
awk 'NR%2==0' file
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐