linux - Bash:我的输出在一行

标签 linux bash shell cut cat

<分区>

我有这段代码可以计算文件中不同大学专业的出现次数:

#!/bin/bash

file=$1
OUT=$( cat $file | cut -d',' -f3 | sort | uniq -c)
echo $OUT

产生这个输出:

4 Computer Information Systems 2 Computer Science 2 History 1 Marketing 2 Social Studies

如何让输出看起来像这样:

4 Computer Information Systems 
2 Computer Science
2 History
1 Marketing
2 Social Studies

每个专业都有自己的路线?

这似乎是一个愚蠢的问题,但我对 bash 脚本编写还很陌生。 TIA 寻求帮助!

最佳答案

不要将值分配给变量,只需这样做:

cut -d',' -f3 "$1" | sort | uniq -c

关于linux - Bash:我的输出在一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40598229/

相关文章:

linux - 如何在启动时运行两个shell脚本?

linux - 如何在不提取整个文件的情况下更改存档 (.ear) 文件中的文件

java - Linux和Windows数据系统可以共存吗

linux - 我如何要求操作系统在另一个内核上运行每个线程?-Linux 操作系统

bash - 获取 shell 脚本目录的父目录

linux - 将项目添加到启动脚本并以特定用户身份运行?

arrays - 在 Bash 中将命令行参数转换为数组

java - 如何解决异常 [Error loading application.groovy due to [java.lang.ArrayIndexOutOfBoundsException] : 0] when deploying war?

linux - 如何在 Linux 中更新环境变量?

linux - 如何在 bash 中对齐文本?