cut
命令在处理大文件时可能会遇到性能问题
while
循环逐行读取文件:while IFS= read -r line; do
echo "$line" | cut -f 1,2
done < "large_file.txt"
awk
命令:awk '{print $1,$2}' large_file.txt
sed
命令:sed 's/^\([^ ]*\).*/\1/' large_file.txt
perl
命令:perl -ne 'print "$1\n" while /([^ ]+)/g' large_file.txt
python
命令:python -c 'import sys; for line in sys.stdin: print(line.split()[0], line.split()[1])' large_file.txt
这些方法都可以有效地处理大文件,具体选择哪种方法取决于你的需求和喜好。