将一个目录下的所有文件内容里的某个字符串a更改为字符串b的实现
时间:2011-09-03
来源:互联网
#!/bin/bash
#Program: This program is to replace the specific string within documents in a dir
#History: 2011-09-03 wfc First Release
dir_in=/home/lasg/work ###################################
cd $dir_in
# 1) get the names of these documents in the dir
names=`ls -l | cut -d ' ' -f 8` ; echo "the documents are:${names}"
echo "-----------------------------------------------------------"
# 2)replace the specific string and > to new document
dir_out=/home/lasg/work2 ##########
sudo mkdir -p $dir_out
# defaults: please make sure only documents in dir,if not, you may do it like this:
# during 1) the names are printed on the screen, you may copy them to here
# for name in `here` ######### like: for name in `doc1 doc2 doc3`
# and add # to the line below
for name in ${names} ###########################
do
new=$name; echo $new
touch $dir_out/$new
# this is an example: replace 'o' with 'oo'#######################
cat $name |sed 's/o/oo/g'> $dir_out/$new ;
unset new
echo "-----------------------------------------------------------"
done
#Program: This program is to replace the specific string within documents in a dir
#History: 2011-09-03 wfc First Release
dir_in=/home/lasg/work ###################################
cd $dir_in
# 1) get the names of these documents in the dir
names=`ls -l | cut -d ' ' -f 8` ; echo "the documents are:${names}"
echo "-----------------------------------------------------------"
# 2)replace the specific string and > to new document
dir_out=/home/lasg/work2 ##########
sudo mkdir -p $dir_out
# defaults: please make sure only documents in dir,if not, you may do it like this:
# during 1) the names are printed on the screen, you may copy them to here
# for name in `here` ######### like: for name in `doc1 doc2 doc3`
# and add # to the line below
for name in ${names} ###########################
do
new=$name; echo $new
touch $dir_out/$new
# this is an example: replace 'o' with 'oo'#######################
cat $name |sed 's/o/oo/g'> $dir_out/$new ;
unset new
echo "-----------------------------------------------------------"
done
作者: wfc1102 发布时间: 2011-09-03
路过
作者: Goando 发布时间: 2011-09-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28