shell语言替换脚本、填补整个命令行

shell语言替换脚本

    • 填补整个命令行
    • 正则查询
    • 服务器指定路径替换内容

填补整个命令行

  • 多用于脚本显示
seq -s "*" `tput cols` |tr -d '[:digit:]'

正则查询

grep -r -E 'register[0-9]{5}' /www/wwwroot

服务器指定路径替换内容

#!/bin/bash
cat > 1.sh << 'EOF'
#!/bin/bash
# 替换脚本
seq -s "*" `tput cols` |tr -d '[:digit:]'
old={旧的内容}
new={新的内容}
path="/www/wwwroot"
echo "开始替换操作:"
echo "旧值: "$old
echo "新值: "$new
echo "搜索路径: "$path



# 查找并替换文件
grep -rl "$old" "$path" | while IFS= read -r file; do
    sed -i "s|$old|$new|g" $file
    echo -e "relink\t>>>\t"$file
done

seq -s "*" `tput cols` |tr -d '[:digit:]'
echo "替换完成"
EOF

# 这里是直接执行了 使用看自己习惯
bash 1.sh

你可能感兴趣的:(shell脚本,linux,shell)