21 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| grep a matches.txt # find lines containing 'a'
 | ||
| grep ab matches.txt # find lines containing 'abc'
 | ||
| grep '^ab$' matches.txt # find lines starting with 'abc'
 | ||
| grep "[hat]" matches.txt # find lines containing h, a or t
 | ||
| grep -E "[abc]{3,4}" matches.txt # find strings with 3 or 4 successive combination of a, b or c
 | ||
| grep -E -n -o "[abc]{3,4}" matches.txt # show line numbers and matches only
 | ||
| ip addr | egrep "([0-9]{1,3}\.){3}[0-9]{1,3}" # find IP addresses
 | ||
| ip addr | egrep "([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}" # find MAC Addresses 
 | ||
| grep "[[:punct:]]" matches.txt # find punctuation
 | ||
| grep "[linux]{3,5}" regex.examples # find l,i,n,u, or x in a pattern between 3 to 5 characters
 | ||
| egrep "[linux]{3,5}" regex.examples # did it work now? 
 | ||
| grep '[[:alpha:]]' regex.examples # find lettes
 | ||
| fgrep '[[:alpha:]]' regex.examples # find the single quote enclosed string explicitly
 | ||
| grep "[[:blank:]]" matches.txt # find space or tab
 | ||
| grep "[[:space:]]" matches.txt # find all whitespace
 | ||
| grep "[[:blank:]]$" matches.txt # find space or tab at the line’s end
 | ||
| grep "[[:space:]]$" matches.txt # find whitespace at the line’s end
 | ||
| grep -i uuid /etc/fstab # find the 'uuid' string
 | ||
| sed -e 's/UUID/uuid' /etc/fstab | grep uuid # case sensitive
 | ||
| sed 's/UUID/UUID UUID/' /etc/fstab | sed 's/UUID/uuid/' # replace only the first match of UUID
 | ||
| sed 's/UUID/UUID UUID/' /etc/fstab | sed 's/UUID/uuid/g' # replace all matches of UUID
 |