Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to locate files in a directory that have strings (with no spaces) longer than x length?

share|improve this question
add comment

2 Answers

up vote 14 down vote accepted

I consider myself a regex noob, but I created a bunch of files with variable length strings in them and I think I got what you wanted, try this:

user@host$ grep -e '[^\ ]\{7,\}' *


For those who don't quite understand this:

-e makes grep search using a regex. [^\ ] means to match a single character except space. \{7,\} means to match a string of 7 or more characters. If you were to put another number afther , it would be strings between 7 and x characters.

share|improve this answer
    
worked great, thanks. –  Susan Jan 31 '10 at 3:42
    
To use any 'space' as a break (space, tab etc), use a similar Perl regex: grep -P '[\S]{7,}' * –  fukawi2 May 2 '13 at 23:44
add comment

I couldn't get the example above to work. I was searching for lines in a CSV file longer than 10000 characters. I messed around quite a bit and got this... Find lines longer than 9999 characters...

grep -a -e '[^\]\{9999,\}' *.csv >../keslerun.csv

And this is what I really needed. Lines in CSV file less than 10000 characters. find lines less than 9999 characters

grep -a -v -e '[^\]\{9999,\}' *.csv >../keslerrun.csv
share|improve this answer
    
Hopefully it completed in less than 12 parsecs? –  maik May 3 '13 at 21:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.