User Tools

Site Tools


grep_usage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
grep_usage [2023/08/17 14:37] – [wordscapes] rajugrep_usage [2023/09/07 21:03] (current) – [repeat previous character N times] raju
Line 57: Line 57:
  % grep -Ei "^([dunes]){2}u([dunes]){2}d$" /usr/share/dict/american-english  % grep -Ei "^([dunes]){2}u([dunes]){2}d$" /usr/share/dict/american-english
 unused unused
 +</code>
 +
 +==== print lines with less than a certain number of characters ====
 +To print lines that contain less than N characters
 +<code>
 +grep -Ev ".{N}" data.txt
 +</code>
 +
 +For example:
 +To print lines that contain less then 6 characters
 +<code>
 +grep -Ev ".{6}" data.txt
 +</code>
 +
 +You can also do
 +<code>
 +grep -v "......" data.txt
 +</code>
 +where the . is repeated N times. This is easier to type for small N.
 +
 +Sample run:
 +<code>
 +$ cat data.txt
 +a
 +ab
 +abc
 +abcd
 +abcde
 +abcdef
 +abcdefg
 +
 +$ grep -v "......" data.txt
 +a
 +ab
 +abc
 +abcd
 +abcde
 +
 +$ grep -Ev ".{6}" data.txt
 +a
 +ab
 +abc
 +abcd
 +abcde
 </code> </code>
  
grep_usage.1692283037.txt.gz · Last modified: 2023/08/17 14:37 by raju