4 ms·
ls | grep 'cheese\|fish' | head -n 5 | while read -r i …
by kps 11y ago
ls | grep 'cheese\|fish' | head -n 5 | while read -r i …
- Symbiote 11y agoWith Zsh: > touch {dark\ red,green,light\ blue}{cheese,fish\ fingers,fruit} > ls -1 *(cheese|fish)*([1,5]) dark redcheese dark redfish fingers greencheese greenfish fingers light bluecheese > for i in *(cheese|fish)*([1,5]) ... Since that's shell globbing, it can cope with any spaces, newlines etc.
- CJefferson 11y agoWow, that is quite impressive, I might have to look into this more. The advantage of using head is I only have to learn it once, to get the first n of lines or files, but it might be worth learning. Thanks.
- Symbiote 11y agoI know 25% of the special Zsh syntax, and know of a further 25% of what exists. I read the whole manpage some years ago, and noted down what seemed useful. I use "man zshexpn" when I forget the syntax for things like this.