Link to home
Start Free TrialLog in
Avatar of tcvinod
tcvinod

asked on

Perl in-place edit for shared file

Hi,
I tried to perform perl inline edit to replace a string.
The file I tried to modify is shared through NAS drive through different platforms (UNIX & WINDOWS).
But, I can pretty much edit the file using VI editor in UNIX.

When I try the command it gives me the following error,
"Can't do inplace edit on test.txt: Not owner."

The commands I tried were,
perl -pi -e 's/CLAD/BKOC/g' test.txt
perl -pi.bak -e 's/CLAD/BKOC/g' test.txt

Are inline edits possible only for the owner of the file, even though groups and others have full write access?
I tried to search a resolution, but with no luck.
Could anyone please advise me?
Avatar of mjcoyne
mjcoyne

Try chmod 777 filename.  Also, what are the permissions for the directory in which the file resides?
using -i require You to have write access to the directory the file resides.
Avatar of tcvinod

ASKER

The file and, directory where the file resides have "rwx" permissions for owner, group and others.
Since it is a NAS mount (also accessed through WINDOWS), I would not be able to reduce the permission. By default every file in that directory has 777.
What you are trying to do is certainly  possible with perls in-place editor.  Is the "not owner"  error generated  in Windows or Nix? Is the file closed before you try and edit it?
Avatar of tcvinod

ASKER

I am trying this in UNIX (Sun Solaris) and getting the error.
The file is closed.
The installed perl version is 5.6.1 to be specific.
can you read the file from perl?
ASKER CERTIFIED SOLUTION
Avatar of mjcoyne
mjcoyne

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tcvinod

ASKER

Hi mjcoyne,
I ran the test script.
It actually created two files test.txt and test.bak.
The test.txt also had the strings substituted while test.bak remains like original.
this is not a perl but a filesystem/permission problem
As you're using NAS, it might be the caching there ...

As mjcoyne's suggestion prooved that you have sufficent permissions to read and write files, you now need to check if you have those permissions on the file where your inline edit won't work. Please post the result of
  ls -l
for that file