Le Nguyen
Le Nguyen

Reputation: 27

How to grep between third appear and fourth appear

I tried to get "hello" ,but this not work ,it between third and fourth appear of character i

echo "ixaifsdaihelloihd" | grep -oP '(?=i{3}).*?(?=i{4})'

Upvotes: 0

Views: 72

Answers (3)

RARE Kpop Manifesto
RARE Kpop Manifesto

Reputation: 2865

if u need the z

echo "ixaifsdaihellozhd" | 

{m,g}awk -Fi 'sub("z.*$", substr(_,$!_=$4))'
 hello

if just i's :

 mawk -Fi '$!NF=$4'

 nawk -Fi '$-_=$4'

 gawk -Fi '$_=$4'

Upvotes: 1

ramsay
ramsay

Reputation: 3845

echo "ixaifsdaihelloihd" | cut -d'i' -f4

Upvotes: 2

Le Nguyen
Le Nguyen

Reputation: 27

echo "ixaifsdaihelloihd" | grep -oP '^(?:[^i]*i){3}\K[^i]+'

or

awk -F'i' '{print $4}' <<< "ixaifsdaihelloihd"

Upvotes: 1

Related Questions