linux - 如何使用 Bash 获取仅包含一组字母的行?

标签 linux bash unix awk sed

我正在尝试查找仅包含一组字母的行。该文件仅包含数字和小写字母。没有空间或任何东西。

很好的例子:

39568250269955376311912572precondition005426787530581443236416842014020466976603

坏例子:

1895853531360579the3170095290529923mathematici2779805995331496368099837070an1084

最佳答案

您可以尝试以下操作吗?

awk 'gsub(/[a-z]+/,"&")==1' Input_file

说明:添加上述代码的说明,仅用于说明运行代码的目的,请使用上述代码本身。

awk '                    ##Starting awk program here.
gsub(/[a-z]+/,"&")==1    ##Using gsub function of awk to substitute all small letters occurrences with same values itself.
                         ##Then checking count of it,if it is equal to 1 then print current line.
                         ##awk works on method of condition and action, in above condition is mentioned but NO action so by default print of current line will happen.
' Input_file             ##mentioning Input_file name here, which is being passed to awk program.

关于linux - 如何使用 Bash 获取仅包含一组字母的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58476975/

相关文章:

Bash 命令行参数,替换变量的默认值

bash - 将函数从 zsh 导出到 bash 以便在 gnu parallel 中使用

c - 建立与 IRC 的连接

unix - 使用 xmllint 从 XML 中获取节点值

linux - 80286 机器(或任何没有内存页面机制的机器)是否有可能是 unix 或 linux

c++ - arm gcc5 的交叉编译 - 正确使用 memcpy

c - 通过/proc/mounts 监控挂载点变化

php - 从主机访问虚拟 linux 机器上的 PHP 网站

linux - "sort filename | uniq"不适用于大文件

php - UTF-8贯穿始终