且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Linux中将包含单词的行从一个文件复制到另一个文件

更新时间:2023-11-27 15:44:22

awk应该做的

awk '/ct/' file1 > file2

如果位置很重要

awk '$3=="ct"' file1 > file2
awk '$3~/ct/' file1 > file2

如果ct是字段#3中的某些内容的一部分,则

最新版本没问题

last version is ok if ct is part of some in field #3

grep

grep ct file1 > file2

不需要

-n,因为它会打印行号

-n is not needed, since it prints line number

sed

sed -n '/ct/p' file1 > file2