Reputation: 87
I want to create a sequence of between n and m alphabetic characters, example 6 and 8, i.e. upper or lower case a through z. The sequence must be separated from the rest of the line by a space or tab character (on each side)
Why my code not working?!
grep -E [ \t][A-Za-z]{6,8}[ \t] myfile.dat
output gives all sequence of words between 6 and 8 and has space on each side, but for \t
it translate it as letter t ?!!
what is wrong ?!
Upvotes: 1
Views: 2183
Reputation: 87
By using $ sign in the beginning:
grep -E $'[ \t][A-Za-z]{6,8}[ \t]' myfile.dat
Upvotes: 2
Reputation: 16834
This works for either tabs or spaces on both sides:
grep -E "[:space:][:alpha:]{6,8}[:space:]" myfile.dat
Also, as suggested by @CharlesDuffy in the comments, changing the [A-Za-z]
to [:alpha:]
will better handle non-standard locales.
Upvotes: 1