Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含1000行的 txt 文件。我想修剪它以获得由原始文件100的行组成的带有行0, 10, 20, 30, etc的文件。
1000
100
0, 10, 20, 30, etc
有可能grep吗?谢谢
grep
它可以通过 awk/sed one-liner 轻松完成:
awk
awk '!(NR%10)' file
sed
sed -n '0~10p' file
或者
sed '0~10!d` file
见下面的例子:(sed 一个班轮将给出相同的输出)
打印前 10 行:
kent$ seq 1000|awk '!(NR%10)'|head -10 10 20 30 40 50 60 70 80 90 100
总行数:
kent$ seq 1000|awk '!(NR%10)'|wc -l 100