Filter number of characters with SED or grep

0

I have a file with strings I need at first to filter for example only rows that have 5 characters And secondly filter only those that have at least 2 characters repeated together Example: Display aazyx or zyaax but does not display azyxa And thirdly filter q lines have at least one vowel.

The latter I know is possible, the other two I do not know if it is possible with thirst. Thanks in advance for your help and attention.

    
asked by anonymous 22.11.2017 / 00:47

2 answers

3

I do not know if I understand very well, but supposing you have a text file in the following format:

file.txt

abcde
aabbc
kkkkk
ggggggggggggg
ccdde

We can filter as follows:

cat arquivo.txt | grep -x '.\{5,5\}' | grep -E '(.){1}' | grep -E '[aeiouAEIOU]{1}'

Note 1: I think it would be better to use egrep instead of grep for regular expressions.

Note: I have no time for the details of a man in grep to search for parameters.

    
22.11.2017 / 18:10
1

Hello, good afternoon.

I hope this is what you need:)

#!/bin/bash
vCharsVogal=(aa ee ii oo uu)
vCharsConso=(bb cc dd ff gg hh ii jj kk ll mm nn pp qq rr ss tt vv xx zz ww yy)
vCharVogal=(a e i o u)
for line in $(cat $1); #//$1 eh o parametro para o arquivo de entrada 
do
        #1 -Primeiro testa se possui 5 chars 
        if (("${#line}" == "5"));
        then
                #2 - Depois verifica se possui repeticao de chars vogais
                continua=1
                for char in ${vCharsVogal[*]}
                do
                        countChar=$(echo "${line}" | awk -F"${char}" '{print NF-1}')
                        if (("$countChar" >= "1"));
                        then
                                #3 - Se entrou aqui, quer dizer que jah possui vogal :) 
                                echo "$line"
                                continua=0
                                break
                        fi
                done
                #Se nao teve nas vogais, ai faz as consoantes
                if(("${continua}" == "1"));
                then
                        for char in ${vCharsConso[*]}
                        do
                                countChar=$(echo "${line}" | awk -F"${char}" '{print NF-1}')
                                if (("$countChar" >= "1"));
                                then
                                        #3 - Vai verificar se existe vogal
                                        for vogal in ${vCharVogal[*]}
                                        do
                                                countVog=$(echo "${line}" | awk -F"${vogal}" '{print NF-1}')
                                                if (("$countVog" >= "1"));
                                                then
                                                        echo "$line"
                                                        continua=0
                                                        break
                                                fi
                                        done
                                        if(("${continua}" == "0"));
                                        then
                                                break
                                        fi
                                fi
                        done
                fi
        fi
done
    
22.11.2017 / 17:41