bash - 根据列值将单个文件分成多个

标签 bash shell awk

我有这样一个文件:

one vijay   three
two vijay   four
five chandu three

输出文件1

one vijay   three
two vijay   four

输出文件2

five chandu three

文件根据第二列的值拆分。

我可以在 shell 脚本中做到这一点。但我想它在 awk 中更简单。 我如何在 awk 中执行此操作?

最佳答案

awk '{print $0>$2".txt"}' file

关于bash - 根据列值将单个文件分成多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5416461/

相关文章:

Python shell 由于递归深度而重新启动

linux - 进度条 + ETA 与 pv 命令在同一行

Android CTS 如何延长 shell-timeout 值

linux - 使用 shell 脚本在 Unix 中搜索文本文件

shell - 可执行 awk 脚本以输出其名称

c - Makefile中的Clean命令无法正常使用

arrays - 神秘 IFS 行为

c - 处理 awk 命令时如何将 'system()' 调用转换为 'fork() + execl()' ?

bash - 使用命令的结果作为 bash 中的参数?

bash 在更改目录 (cd) 后执行 shell 函数