Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 测试架构是否属于特定数据库_Shell_Unix_Scripting_Sed_Awk - Fatal编程技术网

Shell 测试架构是否属于特定数据库

Shell 测试架构是否属于特定数据库,shell,unix,scripting,sed,awk,Shell,Unix,Scripting,Sed,Awk,我问了一个类似的问题,但答案似乎给了我一些问题。我的总体目标是能够从特定数据库中删除特定记录 databases.txt包含: class grades grades name test1 test2 test3 Nick 79 84 85 You 24 83 52 Her 84 98 55 schema.txt包含: class grades grades name test1 test2 test3 Nick 79 84 85 You 24 83 52 Her 84 98 55

我问了一个类似的问题,但答案似乎给了我一些问题。我的总体目标是能够从特定数据库中删除特定记录

databases.txt包含:

class grades
grades name test1 test2 test3
Nick 79 84 85
You 24 83 52
Her 84 98 55
schema.txt包含:

class grades
grades name test1 test2 test3
Nick 79 84 85
You 24 83 52
Her 84 98 55
class.db包含:

class grades
grades name test1 test2 test3
Nick 79 84 85
You 24 83 52
Her 84 98 55
所需的投入将是:

./del.sh class test2 84
我的目标是删除test2和类所属的数据库中任何带有“84”的行

我通过以下方式验证数据库的存在:

awk '{ print $1 }' databases.txt >> temp.txt

if  grep -Fxq $1 temp.txt 
then
    rm temp.txt
    touch temp.txt
else 
    echo "Database name error. Exiting."
    rm temp.txt
    exit 1
fi
我当前的问题是验证test2是否属于属于用户输入的数据库的模式,如果该模式中不存在该字段,则打印错误消息

我先前得到的答复是:

awk 'NR==FNR{a[$1]=$0;next}a[$2]~/$2/{print $0}' schemas.txt databases.txt
但是,它似乎没有真正正确地检查,并且它打印了不必要的数据库文件。我删除记录的代码现在也有点不准确:

var=$(grep -c $3 $1.db)
delrec=$3

echo "There were" $var "records deleted from the $1 database."
sed -i "/$delrec/d" $1.db

类似的东西(这里没有要验证的unix)。如果在linux(或GNU sed)下使用add--posix到sed参数

,我不会使用scripts/sed/awk来完成这样的任务。Perl或Python将是我的选择。在脚本工具中,执行输入验证、转义、引用和类似的操作是相当笨拙的(PITA)。我同意,但是我确实需要在shell脚本中编写=/