0

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

Shriraj
  • 133
  • 4
  • 11

2 Answers2

0

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Markku K.
  • 3,840
  • 19
  • 20
  • Hi I have specified my requirements. COuld you please help now – Shriraj May 28 '13 at 14:56
  • `sed` is a command you can use in your shell, outside of vi. To find out more about it, try typing `man sed`. If I understand your situation, just take my answer and replace "filename*.log" with "EnvName.Fullbkp.schema_121212_1212_Part*.expd". – Markku K. May 28 '13 at 15:03
  • I am not able to use -i option on my clients matchine... is there any other way?? – Shriraj May 29 '13 at 08:23
  • Hi.. This one rocks and I got whatever I wanted.. cool mate.. thanks a lot.. it worked.. (y) – Shriraj Jun 09 '13 at 09:45
  • There is nothing `ksh`-specific in the `for` loop. Any Bourne-compatible shell should understand that code. (If you are new to shells, that means e.g. `sh`, `zsh`, and `bash`, but not `csh` or its derivative `tcsh`.) – tripleee Jun 09 '16 at 04:33
  • @tripleee Right, I mentioned ksh because it is an old Bourne-compatible shell that is available on old versions of AIX. – Markku K. Jun 21 '16 at 20:55
0

It's some kind of extreme optimist who suggests sed -i on AIX.

It's a bit more likely that perl will be installed.

perl -pi -e 's/10022012_0630/22052013_1000/' EnvName.Fullbkp.schema_121212_1212_Part*.expd

If no perl, then you'll just have to do it like a Real Man:

for i in EnvName.Fullbkp.schema_121212_1212_Part*.expd
do
  ed -s "$i" <<'__EOF'
1,$s/10022012_0630/22052013_1000/g
wq
__EOF
done

Have some backups ready before trying these.

tripleee
  • 175,061
  • 34
  • 275
  • 318