You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Bash脚本从CSV提取分数低于50的用户名至output.txt

提取分数低于50的用户到output.txt的实现方法

下面提供两种实用的实现方式,根据你的环境选择即可:

方法1:Python脚本实现

适合所有操作系统,只需安装Python环境:

with open('user.csv', 'r') as infile, open('output.txt', 'w') as outfile:
    # 跳过表头和空行
    next(infile)
    next(infile)
    for line in infile:
        line = line.strip()
        if not line:
            continue
        user, mark = line.split()
        if int(mark) < 50:
            outfile.write(f"{user}\n")

运行脚本后,output.txt会自动生成,包含所有分数低于50的用户名。

方法2:命令行awk工具实现

适用于Linux/macOS,或Windows安装了WSL、Git Bash的环境,直接在终端执行:

awk 'NR>2 && $2 < 50 {print $1}' user.csv > output.txt
  • NR>2:跳过前两行(表头行和空行)
  • $2 < 50:判断第二列的分数是否小于50
  • print $1:输出符合条件的第一列用户名
  • > output.txt:将结果写入output.txt文件

内容的提问来源于stack exchange,提问作者Gowmi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 15:03:35