1

Linux bash script to change a string if another string exists in file

view story
linux-howto

http://stackoverflow.com – I need a linux bash script to loop a folder for all files and check if there is a string in them, change another string of them. For example we check if file contanis AAAA then replace BBBB with CCCC and if didn't have AAAA we change DDDD to EEEE. I wrote some codes but I'm not sure if they work correctly: #!/bin/bash PATH = /path/to/files/* # files has no extension for file in $PATH; do if grep -q "AAAA" $file; then replace "BBBB" "CCCC" -- $file else replace "DDDD" "EEEE" -- $file fi done (HowTos)