mch*_*.ja 8 macos shell terminal command-line
这看起来很傻,但是我还没有找到一个可以做到这一点的工具,所以我想在尝试自己编写代码之前我只想确保一个不存在:
有没有简单的方法cat或less文件的特定行?
我希望这样的行为:
# -s == start && -f == finish
# we want to print lines 5 - 10 of file.txt
cat -s 5 -f 10 file.txt
Run Code Online (Sandbox Code Playgroud)
即使是更简单的东西也会受到赞赏,但我只是不知道有任何工具可以做到这一点:
# print from line 10 to the end of the file
cat -s 10 file.txt
Run Code Online (Sandbox Code Playgroud)
我想,这两个功能的可以用的混合物可以轻松创建head,tail以及wc -l,但也许有建宏认为做到这一点,其中,我不知道?
是的awk和sed可以提供帮助
对于第5到10行
awk 'NR>4&&NR<11' file.txt
sed -n '5,10p' file.txt
Run Code Online (Sandbox Code Playgroud)
第10行到最后一行
awk 'NR>9' file.txt
sed -n '10,$p' file.txt
Run Code Online (Sandbox Code Playgroud)