Skip to Content
bash shell脚本编程经典实例 (第2版)
book

bash shell脚本编程经典实例 (第2版)

by Carl Albing, JP Vossen
January 2021
Intermediate to advanced
581 pages
15h 7m
Chinese
Posts & Telecom Press
Content preview from bash shell脚本编程经典实例 (第2版)
标准输出
39
2.11.2
 解决方案
使用
head
tail
命令。默认情况下,
head
输出指定文件的前
10
行,
tail
输出最后
10
行。如果指定多个文件,则依次输出各文件中相应的行。可以通过
-
number
选项(如
-5
修改默认行数。
tail
还有
-f
-F
选项,这两个选项能够跟踪文件末尾的写入,
2.12
节还
会介绍另一个有意思的加号(
+
)选项。
2.11.3
 讨论
head
tail
cat
grep
sort
cut
uniq
都属于最常用的
Unix
文本处理工具。如果尚
不熟悉这些工具的用法,那么你很快就会好奇自己是如何在没有它们的情况下撑过来的。
2.11.4
 参考
2.12
7.1
8.1
8.4
8.5
17.23
2.12
 跳过文件标题
2.12.1
 问题
文件中有标题行,你希望将其跳过,只处理数据。
2.12.2
 解决方案
使用带有特殊选项的
tail
命令。例如,跳过文件的第一行:
$
tail -n +2 lines
Line 2
Line 3
Line 4
Line 5
$
2.12.3
 讨论
tail
命令的选项
-n
number
(或者
-
number
)可以指定相对于文件末尾的行偏移。因此,
tail -n 10
file
会显示
file
的最后
10
行,这也是不指定任何选项时的默认处理方式。如
果数字以加号(
+
)开头,则表示相对于文件起始的行偏移。
tain -n +1
file
会显示整个
文件,
tain -n +2
file
则是跳过第一行,剩下的以此类推。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

bash 网络安全运维

bash 网络安全运维

Paul Troncone, Carl Albing
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9787115553782