把一个文件的偶数行,或者奇数行提取出来
2014-05-07 09:03
253 查看
>>第一种方法<<
sed -n '1~2p'
sed -n '2~2p'
'FIRST~STEPp'
意为提取行是从FIRST处开始,每隔(步长)为STEP
>>第二种方法<<
awk 'NR%2==1' file
awk 'NR%2==0' file
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处开始,每隔(步长)为STEP
>>第二种方法<<
awk 'NR%2==1' file
awk 'NR%2==0' file
相关文章推荐
- 一种将压缩包中与另外一个目录中相同的文件提取出来的方法
- jmeter添加http请求、java请求,将返回的json数据提取出来并将结果追加到一个文件
- 输入一个数字n 如果n为偶数则除以2,若为奇数则加1或者减1,直到n为1,求最少次数 写出一个函数
- 【笔试】超大文件里的数据去重排序;将log中MAC地址提取出来;取出数据库表T里第20行到29行的数据;如何判断一个二叉树B是不是二叉树A的子树?
- 在整个硬盘搜索一个文件.并将该文件的路径提取出来
- 获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列
- 利用MediaPlayer 获取一个音频或者视频文件的播放时长
- spring加载一个或者多个properties配置文件方法
- c语言:获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列。
- 查看文件夹中的文件的修改时间,并从小到大排列出来到一个文件中
- Java Class文件格式access_flags 描述的是当前类(或者接口)的访问修饰符, 如public, private等, 此外, 这里面还存在一个标志位, 标志当前的额这个class描述的
- window提取一个文件夹内所有文件的名称
- 如何通过命令行或者使用代码打开一个apk文件
- 输出一个数的二进制序列中的奇数位和偶数位
- 将一个数组中所有的奇数放左边,偶数放右边,且原来数字的相对位置不变
- java排序,随机生成一个数组,对其进行排序,偶数在前奇数在后,偶数从小到大排,奇数从大到小排
- 提取一个文件的文件名和扩展名
- 华为:给定一个数组input[],如果数组长度n为奇数,则将数组中最大的元素放到 output[]数组最中间的位置,如果数组长度n为偶数。。
- eclipse打开一个文件后闪退(注意不是启动就闪退,是启动后打开某些类或者配置文件会闪退)解决办法
- 将一个链表中结点的值按奇偶拆分,使其中一个链表结点的值为偶数,另一个为奇数