Issue
I am trying to find words where second or third character is one of "aeiou".
# cat t.txt
test
platform
axis
welcome
option
I tried this but the word "platform" and "axis" is missing in the output.
# awk 'substr($0,2,1) == "e" {print $0}' t.txt
test
welcome
Solution
You may use this awk solution that matches 1 or 2 of any char followed by one of the vowels:
awk '/^.{1,2}[aeiou]/' file
test
platform
axis
welcome
Or else use substr
function to get a substring of 2nd and 3rd char and then compare with one of the vowels:
awk 'substr($0,2,2) ~ /[aeiou]/ ' file
test
platform
axis
welcome
As per comment below OP wants to get string without vowels in 2nd or 3rd position, Here is a solution for that:
awk '{
s=substr($0,2,2)
gsub(/[aeiou]+/, "", s)
print substr($0,1,1) s substr($0, 4)
}' file
tst
pltform
axs
wlcome
option
PS: This sed
would be shorter for replacement:
sed -E 's/^(.[^aeiou]{0,1})[aeiou]{1,2}/\1/' file
Answered By - anubhava Answer Checked By - Marie Seifert (WPSolving Admin)