以下是一个简单的 Linux shell 脚本,用于将多个 txt 文件的内容保存到一个新文件中:

#!/bin/bash

# 创建一个新文件
output_file="output.txt"
> "$output_file"

# 遍历所有的 txt 文件
for file in *.txt; do
  # 跳过新文件本身
  if [ "$file" != "$output_file" ]; then
    # 将文件内容追加到新文件中
    cat "$file" >> "$output_file"
  fi
done

echo "合并完成!结果保存在 $output_file 中。"

使用方法:

  1. 将以上脚本保存为一个文本文件,例如 merge_files.sh
  2. 将所有要合并的 txt 文件与脚本放在同一个目录下。
  3. 打开终端,进入脚本所在的目录。
  4. 运行以下命令,给予脚本执行权限:
    chmod +x merge_files.sh
    
  5. 运行脚本:
    ./merge_files.sh
    
  6. 执行完毕后,所有 txt 文件的内容将被合并到一个新文件 output.txt
请提供一个 linux shell script用于将多个 txt file 的内容保存到一个新文件中

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

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