Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Spotlight replacement

3 views
Skip to first unread message

cele_82

unread,
Dec 4, 2018, 11:18:22 AM12/4/18
to
Hi,
I'm looking for a one liner to add to my .bashrc as function so I can
search for multiple words on a filename list.(my notes)


An alias like this works already on a single string.

alias notes='ls -l ~/Notes/ | grep -i $1


I would like to find a way to make the line above work with multiple
search terms in an AND logic operation...

using $@ instead of $i won't work.

I've tried

ls -l ~/Notes/ | for i in "$@"; do grep $i; done;

but only the first search term gets filtered..




Ideas ?


Michael F. Stemper

unread,
Dec 5, 2018, 8:26:28 AM12/5/18
to
That's because the "ls" is executed once, as can be seen with:

ls -l ~/Notes/ | for i in "$@"
do
echo $i
cat
done

Output for two cases:


username@hostname$ ./one mov
mov
total 12
-rw-rw-r-- 1 username username 24 Dec 4 17:03 appliances
-rw-rw-r-- 1 username username 18 Dec 4 17:02 movies
-rw-rw-r-- 1 username username 25 Dec 4 17:02 python
username@hostname$ ./one mov appl
mov
total 12
-rw-rw-r-- 1 username username 24 Dec 4 17:03 appliances
-rw-rw-r-- 1 username username 18 Dec 4 17:02 movies
-rw-rw-r-- 1 username username 25 Dec 4 17:02 python
appl
username@hostname$

Turn it inside out and you're golden:

for i in "$@"
do
ls -l ~/Notes/ | grep $i
done

username@hostname$ ./one mov
-rw-rw-r-- 1 username username 18 Dec 4 17:02 movies
username@hostname$ ./one mov appl
-rw-rw-r-- 1 username username 18 Dec 4 17:02 movies
-rw-rw-r-- 1 username username 24 Dec 4 17:03 appliances
username@hostname$

--
Michael F. Stemper
This post contains greater than 95% post-consumer bytes by weight.

cele_82

unread,
Dec 8, 2018, 3:49:34 PM12/8/18
to

Hi Michael,
Thanks for the extra tip. This works well, only problem I have it that I
want to use the extra search strings to filter the result of the
previous string.

In the case suggested all the string used are in a logical OR rather
than an AND like I would like to.





0 new messages