我正在尝试为匹配某些文本字段并以某种格式打印它们的分配制作一个 bash 脚本。我正在尝试获取课程编号、标题和学时数(从十进制转换为整数)并将其输出到名为course_list
.
样本输入:
CSC 1010 - COMPUTERS & APPLICATIONS
Computers and Applications. Prerequisite: high school Algebra II. History of computers, hardware components, operating systems, application software, data communication.
3.000 Credit hours
这是我所拥有的:
#!/bin/bash
awk '/CSC/ {print $1$2","$4,$5,$6,$7,$8,$9} /[0-9].(000)/ {print substr(","$1,1,2)}' courses.txt | cat >> course_list
这是我得到的输出:
CSC1010,COMPUTERS & APPLICATIONS
,3
这是我想要的输出:
CSC1010,COMPUTERS & APPLICATIONS,3
我在想我已经很接近了,但我无法弄清楚如何在没有\n
.