Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

rename - Editing/Replacing content in multiple files in Unix AIX without opening it

I have multiple files in Unix directory. files names are as below.
EnvName.Fullbkp.schema_121212_1212_Part1.expd EnvName.Fullbkp.schema_121212_1212_Part2.expd EnvName.Fullbkp.schema_121212_1212_Part3.expd

In each of the above file there is a common line like below. eg

EnvName.Fullbkp.schema_121212_1212_Part1.expd

is having below data

Log=EnvName.Fullbkp.schema_10022012_0630_Part1.log  
file=EnvName.Fullbkp.schema_10022012_0630_Part1.lst  

EnvName.Fullbkp.schema_121212_1212_Part2.expd

is having below data

Log=EnvName.Fullbkp.schema_10022012_0630_Part2.log  
file=EnvName.Fullbkp.schema_10022012_0630_Part2.lst

I want to replace the 10022012_0630 from EnvName.Fullbkp.schema_121212_1212_Part*.expd files with 22052013_1000 without actully opening those files. Changes should happen in all EnvName.Fullbkp.schema_121212_1212_Part*.expdp files in a directory at a time

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you mean you don't want to manually open the files:

sed -i 's/10022012_0630/22052013_1000/' filename*.log

update: since the "-i" switch is not available on AIX, but assuming you have ksh (or a compatible shell):

mkdir modified
for file in filename*.log; do
    sed 's/10022012_0630/22052013_1000/' "$file" > modified/"$file"
done

Now the modified files will be in the modified directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...