#!/bin/bash

检查 t.txt 是否存在

if [ ! -f 't.txt' ]; then echo 't.txt 文件不存在' exit 1 fi

使用 sed 将非句号结尾的句子拼接

sed -e ':a;N;$!ba;s/([^。])\n([^A-Z])/\1\2/g' 't.txt' > 't1.txt'

使用 sed 将逗号前断开换行

sed -e 's/,/\n/g' 't1.txt' > 't2.txt'

删除临时文件

rm 't1.txt'

echo '处理完成,请查看 t2.txt 文件。'

Shell 脚本:合并句子并处理逗号

原文地址: https://www.cveoy.top/t/topic/lW89 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录