Results 1 to 3 of 3
I have a file with a random word on each line (3k+ lines).
How can I get the lines with only five characters? I tried using grep '.....' file | ...
- 11-02-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 9
[SOLVED] Pattern Searching
I have a file with a random word on each line (3k+ lines).
How can I get the lines with only five characters? I tried using grep '.....' file | more, but it returns all the words (even those less than 5 characters).
Edit: I also tried grep '.{5}' file | more but it doesn't show anything. And grep '.\{5\}' file | more returns all lines with four or more characters (I'm really confused about why it's doing this).
Edit: Okay, ended up using sed -n '/^.\{5\}$/p' file | more. Thanks for any help.Last edited by whocares357; 11-02-2010 at 08:19 PM.
- 11-02-2010 #2
in case this is homework, the hint i will give you is to lookup negative lookahead assertions
also probably look into using perl grep option
- 11-02-2010 #3Just Joined!
- Join Date
- Oct 2010
- Posts
- 9
Can you at least explain why grep '.\{5\}' file | more returns four or more? I could maybe understand if it returned five or more, but why does it return four?
Edit: I'm guessing that I have some hidden characters in there. How can I reveal them (vi or cat)? Nevermind: set list in vi.Last edited by whocares357; 11-02-2010 at 08:15 PM.


