terminal
Welcome to Linux Practice Terminal!
Type "help" to see available commands.
user@linux:~$
高级文本处理
使用head、tail、grep和wc构建复杂管道进行多阶段文本处理。
步骤 1
复习:将cat的输出通过管道传递给grep查找ERROR行。
输入:cat documents/log.txt | grep ERROR
cat documents/log.txt | grep ERROR
步骤 2
将日志文件通过管道传递给head,只查看前3行。
步骤 3
提取第4-5行:通过head -n 5然后tail -n 2进行管道处理。
步骤 4
使用3阶段管道统计INFO行:cat | grep | wc。
步骤 5
使用ls | grep筛选目录列表中的"txt"文件。
步骤 6
统计documents中有多少个txt文件。
步骤 7
在管道中使用grep -n查找带行号的WARN行。
步骤 8
在管道中使用grep -v统计非INFO行数。
步骤 9
将管道输出保存到文件:将grep结果写入errors.txt。