Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find words that are 6 characters in length

I have a file.txt

fhadja
ksjfskdasd
adasda
sada
s
adasaaa

I need to extract only the words that are 6 character length from there.

EXAMPLE of what i need to obtain as a result:

fhadja
adasda

Thank you.

like image 458
Chris Avatar asked Dec 15 '22 11:12

Chris


2 Answers

You can use:

grep -E '^.{6}$' file
fhadja
adasda

Or using awk:

awk 'length($0)==6' file
fhadja
adasda

Or using sed:

sed -rn '/^.{6}$/p' file
fhadja
adasda
like image 99
anubhava Avatar answered Dec 29 '22 14:12

anubhava


Try this with GNU grep:

grep -E '^.{6}$' file

Output:

fhadja
adasda
like image 43
Cyrus Avatar answered Dec 29 '22 12:12

Cyrus