linux批量修改文件名及文件内容

文章目录

  • 1.目标
  • 2.行动

1.目标

1.1 讲当前目录下包含pyia的文件替换为PCMSMES
[oracle@gsierp conf]$ ls -alh

ls
-rwxr-xr-x 1 oracle dba  236 Sep 17  2021 perf_pyia_act_session.json
-rwxr-xr-x 1 oracle dba  222 Nov 11  2021 perf_pyia_job.json
-rwxr-xr-x 1 oracle dba  244 Sep 22  2016 perf_pyia_joblong.json
-rwxr-xr-x 1 oracle dba  233 Aug  8  2022 perf_pyia_logswitches.json
-rwxr-xr-x 1 oracle dba  244 Sep 22  2016 perf_pyia_object.json
-rwxr-xr-x 1 oracle dba  228 Sep 22  2016 perf_pyia_rmanbackup.json
-rwxr-xr-x 1 oracle dba  232 Sep 22  2016 perf_pyia_scheduler_job.json
-rwxr-xr-x 1 oracle dba  245 Sep 22  2016 perf_pyia_session.json
-rwxr-xr-x 1 oracle dba  248 Sep 22  2016 perf_pyia_sessionlong.json
-rwxr-xr-x 1 oracle dba  230 Sep 22  2016 perf_pyia_tablespace.json

1.2 并且将所有文件内的pyia字样替换为PCMSMES

[oracle@gsierp conf]$ cat ./* |grep database
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"
"database":"pyia"

2.行动

2.1 替换文件名

for i in ./perf_pyia_*; do mv $i "$(echo "$i" | sed 's/perf_pyia/perf_PCMSMES/')" ; done

2.2 替换文件内容

 cat ./*|grep pyia|sed -i 's/pyia/PCMSMES/g'

你可能感兴趣的:(Linux,linux,运维,服务器)