awk - 删除长度少于两个字符且不包含元音的单词
问题描述
sed -e 's/ [a-zA-Z0-9]\{1\} / /g'
尽管我不确定如何在一个命令中仅删除不包含元音且长度小于 2 的单词,但您可以删除长度小于 2 的
单词。
因此一个句子
this is my w example of a sentence p
会像这样结束
this is my example of a sentence
解决方案
请您尝试以下操作。
awk '
{
val=""
for(i=1;i<=NF;i++){
if($i!~/[aieou]/ && length($i)<2){ a="" }
else{ val=(val?val OFS:"")$i }
}
print val
}
' Input_file
说明:为上述添加详细说明。
awk ' ##Starting an awk program from here.
{
val="" ##Nullifying val value here.
for(i=1;i<=NF;i++){ ##Starting a for loop from here.
if($i!~/[aieou]/ && length($i)<2){ a="" } ##Checking condition if field is NOT containing any vowels and length is lesser than 2 then do nothing.
else{ val=(val?val OFS:"")$i } ##Else(in case above condition is FALSE) create val which contains current field value.
}
print val ##Printing val here.
}
' Input_file ##Mentioning Input_file name here.
推荐阅读
- java - 为什么指令重新排序的 volatile Happens-Before 命令失败?
- sapui5 - 理解 OpenUI5 的 Controller.getView()
- arrays - Swift:具有相同值的顺序数组
- networking - 无法 ping 到 machine.local 但可以 ping 机器
- javascript - 输入范围滑块未正确显示
- java - 如何为自定义插件修改 Gradle 插件 {} 管理存储库?
- c# - 未应用全局标签样式
- c# - 运行测试后如何关闭 Android SDK 模拟器
- python - 将定义集中的值设置为熊猫数据框中列的给定值(fe NaN)
- python-3.x - 在gensim word2vec中随机选择向量