You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							19 lines
						
					
					
						
							314 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							19 lines
						
					
					
						
							314 B
						
					
					
				
								#!/bin/bash
							 | 
						|
								
							 | 
						|
								function usage {
							 | 
						|
									builtin echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								[[ $# -ne 3 ]] && usage && exit 2
							 | 
						|
								
							 | 
						|
								REGEX=$1
							 | 
						|
								STRING=$2
							 | 
						|
								FILE=$3
							 | 
						|
								
							 | 
						|
								if ! grep -Eq "$REGEX" "$FILE"; then
							 | 
						|
									builtin echo -e "$STRING" >>"$FILE"
							 | 
						|
									echo 'appended'
							 | 
						|
								else
							 | 
						|
									sed -Ei "s|$REGEX|$STRING|g" "$FILE"
							 | 
						|
									echo 'replaced'
							 | 
						|
								fi
							 |