4 ms·
But, I need to remember to do that. How about (for example): $ for i in $(ls | grep 'cheese\|fish' | head -n 5) ... I'm sure there is a way to make this
by CJefferson 11y ago
But, I need to remember to do that.
How about (for example):
$ for i in $(ls | grep 'cheese\|fish' | head -n 5) ...
I'm sure there is a way to make this work correctly (take 5 filenames containing either cheese or fish), but I'd need to put more thought into making it work correctly.
- kps 11y agols | 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.