linux_text_process - JasonWayne/personal-wiki GitHub Wiki

Linux Text Process

cut

see https://www.computerhope.com/unix/ucut.htm and https://shapeshed.com/unix-cut/

data.txt:
one	two	three	four	five
alpha	beta	gamma	delta	epsilon

cut -f 3 data.txt
three
gamma

cut -d'\t' -f 1,3 data.txt
cut -d'\t' -f 1-3 data.txt

Grep

Awk

Sed

入门

Sed简明教程
一篇文章学会shell工具篇之sed
看例子学sed

简单的Reference

sed单行脚本 Sed - An Introduction and Tutorial by Bruce Barnett

详细的官方教程, 详细的Reference

https://www.gnu.org/software/sed/manual/sed.html Regular Expressions in sed

Scenario

找到当前目录下所有出现过某个pattern两次以上的文件

grep -r -o -c "pattern" ./* | awk -F: {if ($2 > 1) {print $1}}'