I have a quick (and hopefully simple) question about regexps. I'm trying to think of a regexp which matches all of a set of tokens irrespective of order.So for example I have a file with the names of the US states thusAbbreviation:State name:Capital:Became a stateAL:Alabama:Montgomery:December 14, 1819AK:Alaska:Juneau:January 3, 1959AZ:Arizona:Phoenix:February 14, 1912...WI:Wisconsin:Madison:May 29, 1848WY:Wyoming:Cheyenne:July 10, 1890Say I wanted to find all states which had the letters A, R and N in their names (case insensitive).I could do a $ cut -d: -f2 states.txt | tail -n +2 | grep -i a | grep -i r | grep -i nwhich sure enough producesArizonaArkansasCaliforniaMarylandNebraskaNew HampshireNorth CarolinaNorth DakotaRhode IslandSouth CarolinaVirginiaWest VirginiaIs there any way of matching all three letters if they occur in any order using a single regexp?
regexp which matches all tokens independent of order
grep;regular expression
You should use awk:$ awk '/a|A/ && /R|r/ && /N|n/' fileArizonaArkansasCaliforniaMarylandNebraskaNew HampshireNorth CarolinaNorth DakotaRhode IslandSouth CarolinaVirginiaWest VirginiaWith gawk, you can use IGNORECASE:gawk '/a/ && /r/ && /n/' IGNORECASE=1 file