Is it possible to locate files in a directory that have strings (with no spaces) longer than x length?
2 Answers
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.
- 818
- 2
- 9
- 21
-
1To use any 'space' as a break (space, tab etc), use a similar Perl regex: `grep -P '[\S]{7,}' *` – fukawi2 May 02 '13 at 23:44
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 >../my-file.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 >../my-file.csv