Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed command error

Status
Not open for further replies.

anatazi

Programmer
Jun 24, 2002
33
0
0
US
Hi all, I wrote this script (prog3a) that replaces all of the occurences of a search-string with the replace-string in the file specified on the command line. the sed command should send the output to a temp file , then the temp file is moved to $file.keep. when i run the script I get the following error message:
prog3a: to: not found
cp: . is a directory (not copied).
could not create the backup file

Below is the portion of the script where the problem is. I would appreciate any pointers.Thanks a lot.

for $file
do

if cp "$file" "$file.keep"
then
:
else
echo "could not create the backup file" 1>&2
fi


if [ -r "$file" -a -w "$file" ]; then

sed "s/$search_string/$replace_string/g" $file > temp
mv temp "$file.keep"
fi
done
 
Hi:

The problem isn't with sed; What's probably happening is you're trying to copy a directory, so the error message is valid.

The obvious fix is however, you create $file, make sure it doesn't contain any directories.

Regards,


Ed
 


add an if to make sure $file isn't a directory.

if [ -d $file ] ; then
next
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top