簡體   English   中英

外殼程序腳本中帶有/ w參數的sed命令

[英]sed command with /w parameter in shell script

我有一個shell腳本,在這里我使用帶有/ w標志的sed命令來創建輸出文件。 當我嘗試在腳本中使用該文件時,找不到文件,但是在腳本退出后,將在目錄中創建該文件。

我可以使用腳本中創建的文件嗎? 我需要做什么才能使其正常工作?

#!/usr/bin/bash
fileQual=Test_load

dataFile=$fileQual.dat
corruptDataFile=$fileQual.err

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"
    else
        echo "${fname} not found"
    fi
    #resFun=atch
    # 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-$TIME.zip"        # defining the format of the file name while backing up

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

zip -9 $FILENAME $corruptDataFile $dataFile

輸出是

file corruptDataFile = Test_load.err

ls: Test_load.err: No such file or directory


Test-2016-06-29-204904.zip

**********zipincl   Test_load.err not found  Test_load.err  
+ zip -9 Test-2016-06-29-204904.zip Test_load.err Test_load.dat
        zip warning: name not matched: Test_load.err

腳本完成后,當我查看目錄時,文件實際上就在這里。 有什么辦法可以在zip命令中使用它嗎?

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

從上面的行中刪除'${corruptDataFile}'之后'${corruptDataFile}'空格。 它創建的文件名末尾有空格。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM