Shell脚本用于读取文件中的一行并替换为属性文件中的值

时间:2016-08-17 05:45:21

标签: shell sh

我有一个文件names.txt,它有多行名称,如下所示:

汤姆
SAM
哈利
sarrah

我有一个属性文件,它具有几个名称的等价值,如下所示:

汤姆=撬
SAM =萨曼莎

我必须阅读文件names.txt的每一行,如果找到 sam或tom ,它必须替换属性文件中的值,我的最终结果应如下所示:


萨曼莎
哈利
sarrah

请帮我识别相同的脚本

2 个答案:

答案 0 :(得分:1)

不是非常强大,但你可以这样做:

flurry

答案 1 :(得分:0)

请注意确定您是否得到了答案,但我发布了一个可以完成任务的脚本。脚本的输入是namefile和propertyfil。

library(caret)  # run on version 6.0-71

model_list <- getModelInfo()
df <- data.frame(models = names(model_list), 
                 fit = rep("", length(model_list)), 
                 stringsAsFactors = FALSE)

for (i in 1:length(model_list)) {
  df$fit[i] <- as.expression(functionBody(model_list[[i]]$fit))
}

# find xgboost matrix   
df$models[grep("xgb.DMatrix", df$fit)]
[1] "xgbLinear" "xgbTree"  

# find all models where fit contains as.matrix(x)
df$models[grep("as.matrix\\(x\\)", df$fit)]

[1] "bdk"               "binda"             "blasso"            "blassoAveraged"    "bridge"            "brnn"             
[7] "dnn"               "dwdLinear"         "dwdPoly"           "dwdRadial"         "enet"              "enpls.fs"         
[13] "enpls"             "foba"              "gaussprLinear"     "gaussprPoly"       "gaussprRadial"     "glmnet"           
[19] "knn"               "lars"              "lars2"             "lasso"             "logicBag"          "LogitBoost"       
[25] "lssvmLinear"       "lssvmPoly"         "lssvmRadial"       "mlpSGD"            "nnls"              "ordinalNet"       
[31] "ORFlog"            "ORFpls"            "ORFridge"          "ORFsvm"            "ownn"              "PenalizedLDA"     
[37] "ppr"               "qrnn"              "randomGLM"         "relaxo"            "ridge"             "rocc"             
[43] "rqlasso"           "rqnc"              "rvmLinear"         "rvmPoly"           "rvmRadial"         "sda"              
[49] "sddaLDA"           "sddaQDA"           "sdwd"              "snn"               "spikeslab"         "svmLinear"        
[55] "svmLinear2"        "svmLinear3"        "svmLinearWeights"  "svmLinearWeights2" "svmPoly"           "svmRadial"        
[61] "svmRadialCost"     "svmRadialSigma"    "svmRadialWeights"  "xgbLinear"         "xgbTree"           "xyf"      

执行:触发以下命令执行shell:

filenm=$1       --Name file as input
lkfilenm=$2     --Property file for lookup

while read line
do

echo $line

z=`grep "$line" /home/$lkfilenm | cut -d"=" -f2`

echo $z

if [ -z "$z" ]; then       
    echo ok
else       
    sed -e "s/$line/$z/g" /home/$filenm > filenme
fi

done<$filenm

mv filenme $filenm
rm -f filenme