>>第一种方法<<
- 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
本文详细介绍了如何使用sed和awk命令从文件中提取特定行。通过使用sed的正则表达式匹配和awk的逻辑操作符,可以高效地选择满足条件的行,包括奇数行、偶数行和其他特定行的提取。
1935

被折叠的 条评论
为什么被折叠?



