提取与图案匹配的线的一部分

伊巴拉法

我有一个配置文件,需要使用bash
Ex解析出一些值内部config.txt

some_var= Not_needed
tests= spec1.rb spec2.rb spec3.rb
some_other_var= Also_not_needed

基本上,我只需要获取“ spec1.rb spec2.rb spec3.rb”,而无需其他所有行,并且从该行中删除“ tests =“。

我有这个功能,但是我希望有一个更简单的方法可以做到这一点。

while read run_line; do
if [[ $run_line =~ ^tests=* ]]; then
  echo "FOUND"
  all_selected_specs=`echo ${run_line} | sed 's/^tests= /''/'`
fi
done <${config_file}
echo "${all_selected_specs}"
使用者

这也应该工作

grep "^tests" ${config_file} | sed -e "s/^tests= //"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章