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.
		
		
		
		
		
			
		
			
				
					
					
						
							22 lines
						
					
					
						
							296 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							22 lines
						
					
					
						
							296 B
						
					
					
				
								#!/bin/bash
							 | 
						|
								
							 | 
						|
								usage() {
							 | 
						|
									echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								if [[ $# -ne 3 ]]; then
							 | 
						|
									usage
							 | 
						|
									exit 2
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								REGEX=$1
							 | 
						|
								STRING=$2
							 | 
						|
								FILE=$3
							 | 
						|
								
							 | 
						|
								if ! grep -Pq "$REGEX" "$FILE"; then
							 | 
						|
									printf "%s\n" "$STRING" >>$FILE
							 | 
						|
									echo appended
							 | 
						|
								else
							 | 
						|
									sed -i "s|$REGEX|$STRING|g" $FILE
							 | 
						|
									echo replaced
							 | 
						|
								fi
							 |