linux - 如何从shell脚本中的一行中提取两个部分数值
问题描述
我有多个这种格式的文本文件。我想提取与此模式“通过过滤器和 QC”匹配的行。
文件1:
Before main variant filters, 309 founders and 0 nonfounders present.
0 variants removed due to missing genotype data (--geno).
9302015 variants removed due to minor allele threshold(s)
(--maf/--max-maf/--mac/--max-mac).
7758518 variants and 309 people pass filters and QC.
Calculating allele frequencies... done.
我能够 grep 行,但是当我尝试分配给行变量时它不起作用。
grep 'people pass filters and QC' File1
line="$(echo grep 'people pass filters and QC' File1)"
我是 shell 脚本的新手,如果你能帮我这样做,我将不胜感激。
我想创建一个制表符分隔的文件
"File1" "7758518 variants" "309 people"
解决方案
GNU awk
gawk '
BEGIN { patt = "([[:digit:]]+ variants) .* ([[:digit:]]+ people) pass filters and QC" }
match($0, patt, m) {printf "\"%s\" \"%s\" \"%s\"\n", FILENAME, m[1], m[2]}
' File1
推荐阅读
- c# - Swashbuckle / swagger 文档缺失信息
- sql - SQL Server,将 CASE 语句聚合到一行中
- php - 类型转换雄辩的关系 laravel
- java - 如何创建一串文本并将位置传递给 ListView 适配器?
- c++-cli - 无法将参数 1 从 'System::IO::StreamWriter ^' 转换为 Windows 形式的 'System::IO::Stream ^
- python - 我的结果被截断为一行。我如何让它打印所有内容?
- xcode - Xcode 11 添加新的约束集零:使用设置值而不是默认/标准
- php - 在插入符号处插入而不是替换整个文本区域
- c# - 使用 RestSharp 调用 OAuth1 api,使用的参数范围不起作用
- mysql - 带有字符串变量的mysql查询