linux一个一个修改字符串,将一个目录下的所有文件内容里的某个字符串a更改为字符串b的实现...

将一个目录下的所有文件内容里的某个字符串a更改为字符串b的实现

发布时间:2011-09-03 14:56:11来源:红联作者:wfc1102

#!/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值