view raw
adbdkb adbdkb - 10 months ago 36
Bash Question

sed command with /w parameter in shell script

I have a shell script where I am using a sed command with /w flag to create an output file. When I try to use that file within the script, I get File not found, but after the script exists, it is created in the directory.

Can I use the file created inside the script? What do I need to do for that to work?



cp "${dataFile}" "${dataFile}".cpy

LANG=C sed -n '/[\x00-\x08\x80-\xFF\x0B-\x0C\x0E-\x1F\x21-\x2B\x2F\x3A-\x40\x5B-\x60\x7B\x7D-\x7F]/w '${corruptDataFile}' ' "${dataFile}".cpy
echo "file corruptDataFile = ${corruptDataFile}"
ls ${corruptDataFile}

function checkNattach()
local fname="$1"
local atch
if [ -f "$1" ];then
atch="-a ${fname} "
echo "${fname} exists"
echo "${fname} not found"
# echo " in function checkNattach atch $atch "
# echo " in function checkNattach resFun $resFun "
echo $atch

TIME=`date +%F-%H%M%S` # time stamp to the backup file
FILENAME="Test-$" # defining the format of the file name while backing up

zipincl="${zipincl} $(checkNattach ${corruptDataFile})"
echo "**********zipincl ${zipincl} ${corruptDataFile} "

zip -9 $FILENAME $corruptDataFile $dataFile

And the output is

file corruptDataFile = Test_load.err

ls: Test_load.err: No such file or directory

**********zipincl Test_load.err not found Test_load.err
+ zip -9 Test_load.err Test_load.dat
zip warning: name not matched: Test_load.err

After the script finishes, when I look in the directory, the file actually is there. Is there a way I can use it in the zip command?

LANG=C sed -n '/[\x00-\x08\x80-\xFF\x0B-\x0C\x0E-\x1F\x21-\x2B\x2F\x3A-\x40\x5B-\x60\x7B\x7D-\x7F]/w '${corruptDataFile}' ' "${dataFile}".cpy

Remove space after '${corruptDataFile}' from above line. It's creating filename with space at end.