![]() ![]() You can use -F which classifies the file with different special character for different kind of files. Instead of doing the ‘ls -l’ and then the checking for the first character to determine the type of file. The awk/ sed/ perl ones don't reflect whether any line matched the patterns in their exit status. Example-11: Visual Classification of Files With Special Characters: ls -F. Please beware that all those will have different regular expression syntaxes. Or perl: perl -ne 'print if /pattern1/ & /pattern2/' Or with sed: sed -e '/pattern1/!d' -e '/pattern2/!d' The best portable way is probably with awk as already mentioned: awk '/pattern1/ & /pattern2/' If the patterns don't overlap, you may also be able to do: grep -e 'pattern1.*pattern2' -e 'pattern2.*pattern1' This finds all files (-type f) that are executable: find. I doubt thats the reason most people come here. 5 Eric Regardless of the OPs requirements, inverting a grep expression is useful for much more than finding files. *s as & matches strings that match both and exactly, a&b would never match as there's no such string that can be both a and b at the same time). If you absolutely must use ls and grep, this works: ls -Fla grep '\Sx\S' It matches lines where the first word (non-whitespace) contains at least one 'x'. Combining ls and grep for this purpose seems hacky at best. With ast grep: grep -X '.*pattern1.*&.*pattern2.*' With GNU grep, when built with PCRE support, you can do: grep -P '^(?=.*pattern1)(?=.*pattern2)' To find the lines that match each and everyone of a list of patterns, agrep (the original one, now shipped with glimpse, not the unrelated one in the TRE regexp library) can do it with this syntax: agrep 'pattern1 pattern2' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |