将文件中所有除了行首的大写字母,其他的都改成小写字母
#!/bin/bash
# 检查参数是否正确
if [ $# -ne 2 ]; then
echo "用法: $0 input_file output_file"
exit 1
fi
input_file="$1"
output_file="$2"
# 处理文件
awk '{
if (length($0) > 0) {
first_char = substr($0, 1, 1)
rest = substr($0, 2)
printf "%s%s\n", toupper(first_char), tolower(rest)
}
}' "$input_file" > "$output_file"
echo "处理完成,输出文件为: $output_file"
使用说明:
- 将脚本保存为
convert.sh。 - 给予执行权限:
chmod +x convert.sh。 - 运行脚本:
./convert.sh input.txt output.txt。


