如何在Linux中获取文本文件的第N行(特定行)和倒数第二行的组合?

huangapple go评论67阅读模式
英文:

How to get combination of Nth line(specific line) and last but one line from text file in Linux?

问题

我需要从文件中获取第17行和倒数第二行,并将它们合并成文件中的第99行。

英文:

In a file, I have 100 lines. But I want 17th and last but one as 99th line from the file.
I need the command combinedly.

答案1

得分: 1

获取第17行:

head -17 file | tail -1

获取第99行:

tail -2 file | head -1

用分号组合这些命令:

head -17 file | tail -1 ; tail -2 file | head -1
英文:

Get the 17th line:

head -17 file | tail -1

Get the 99th line:

tail -2 file | head -1

Combine the commands with a semicolon:

head -17 file | tail -1 ; tail -2 file | head -1

huangapple
  • 本文由 发表于 2020年1月3日 14:24:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定