I’m using the command grep 3 times on the same line like this
ls -1F ./ | grep / | grep -v 0_*.* | grep -v undesired_result
is there a way to combine them into one command instead of having it to pipe it 3 times?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no way to do both a positive search (
grep <something>) and a negative search (grep -v <something>) in one command line, but if yourgrepsupports-E(alternatively,egrep), you could dols -1F ./ | grep / | grep -E -v '0_*.*|undesired_result'to reduce the sub-process count by one. To go beyond that, you’d have to come up with a specific regular expression that matches either exactly what you want or everything you don’t want.Actually, I guess that first sentence isn’t entirely true if you have
egrep, but building the proper regular expression that correctly includes both the positive and negative parts and covers all possible orderings of the parts might be more frustrating than it’s worth…