linux - 如何使用 Bash 获取仅包含一组字母的行?
问题描述
我试图找到只包含一组字母的行。该文件仅包含数字和小写字母。没有空间或任何东西。
好例子:
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.
推荐阅读
- android - 在协程上下文中运行模拟方法在 kotlin 中返回 null
- java - Android SDK 中的 Alpha 合成
- spring-boot - Spring Boot 应用程序无法以 2.1.8 启动
- android - 如何修复“未找到方向性小部件”。问题?
- javascript - 如何将自动完成角度材料与动态数据源 (SQL) 一起使用
- java - 如果 vertx setPeriodic 延迟小于其处理程序执行时间会发生什么
- ios - SwiftUI:minimumScaleFactor 没有均匀地应用于堆栈元素
- mysql - 修改旧的 Rails 迁移,然后添加一个调用旧迁移的新迁移
- regex - 使用带引号或不带引号的 grep 正则表达式模式之间的区别?
- c - 在c编程中将十六进制转换为二进制