grep_usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
grep_usage [2021/02/22 17:33] – raju | grep_usage [2023/09/07 21:03] (current) – [repeat previous character N times] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== dummy ==== | ||
+ | * [[Remove lines with duplicate letters]] | ||
+ | * [[grep on find results]] | ||
+ | |||
==== wordscapes ==== | ==== wordscapes ==== | ||
+ | tags | word scape, wordscape | ||
< | < | ||
% grep -i " | % grep -i " | ||
elves | elves | ||
sells | sells | ||
+ | </ | ||
+ | |||
+ | Remove lines with duplicate letters | ||
+ | < | ||
+ | % grep -Ei " | ||
+ | ... | ||
+ | shire | ||
+ | shirk | ||
+ | skier | ||
+ | </ | ||
+ | |||
+ | compare this with | ||
+ | < | ||
+ | % grep -Ei " | ||
+ | ... | ||
+ | shire | ||
+ | shirk | ||
+ | shirr | ||
+ | sires | ||
+ | sises | ||
+ | skier | ||
+ | skies | ||
+ | </ | ||
+ | |||
+ | which also shows words where some letters are repeated twice. | ||
+ | |||
+ | ==== repeat previous character N times ==== | ||
+ | Use (character){N} and call grep with -E | ||
+ | |||
+ | < | ||
+ | % grep -Ei " | ||
+ | Circe | ||
+ | niche | ||
+ | niece | ||
+ | </ | ||
+ | |||
+ | is equivalent to | ||
+ | < | ||
+ | % grep -i " | ||
+ | Circe | ||
+ | niche | ||
+ | niece | ||
+ | </ | ||
+ | |||
+ | Another example: | ||
+ | < | ||
+ | % grep -Ei " | ||
+ | unused | ||
+ | </ | ||
+ | |||
+ | ==== print lines with less than a certain number of characters ==== | ||
+ | To print lines that contain less than N characters | ||
+ | < | ||
+ | grep -Ev " | ||
+ | </ | ||
+ | |||
+ | For example: | ||
+ | To print lines that contain less then 6 characters | ||
+ | < | ||
+ | grep -Ev " | ||
+ | </ | ||
+ | |||
+ | You can also do | ||
+ | < | ||
+ | grep -v " | ||
+ | </ | ||
+ | where the . is repeated N times. This is easier to type for small N. | ||
+ | |||
+ | Sample run: | ||
+ | < | ||
+ | $ cat data.txt | ||
+ | a | ||
+ | ab | ||
+ | abc | ||
+ | abcd | ||
+ | abcde | ||
+ | abcdef | ||
+ | abcdefg | ||
+ | |||
+ | $ grep -v " | ||
+ | a | ||
+ | ab | ||
+ | abc | ||
+ | abcd | ||
+ | abcde | ||
+ | |||
+ | $ grep -Ev " | ||
+ | a | ||
+ | ab | ||
+ | abc | ||
+ | abcd | ||
+ | abcde | ||
</ | </ | ||
grep_usage.1614015237.txt.gz · Last modified: 2021/02/22 17:33 by raju