shell 读取文件第几列

时间:2023-12-21 10:32:14

读取文件的第2列和第4列:

cat filename.txt | awk '{ print $2 $4 }'

求文件file1.txt的第二列 和 file2.txt(单列文件)的交集:

cat file1.txt | awk '{print $2}' | sort > file1_ret.txt
cat file2.txt | sort > file2_ret.txt
comm - file1_ret.txt file2_ret.txt