Rename multiple files in a directory
Replace string inside multiple files
In modern linux systems:
~#cd /path/to/your/folder
~#sed -i 's/foo/bar/g' *
-i means inplace
or
rename 's/fgh/jkl/' fgh*
or
~#grep -rl "old_string" . | xargs sed -i 's/old_string/new_string/g'
- grep -rl: search recursively, and only print the files that contain “old_string”
- xargs: take the output of the grep command and make it the input of the next command (ie, the sed command)
- sed -i 's/old_string/new_string/g': search and replace, within each file, old_string by new_string
In Z/OS unix system: 1. Create a bash script as below and save it as (sed.sh):
#!/bin/sh
sed "s/http/https/g" $1 > /changed/$1
- Use find to find files and execute bash script for each file
~#find . -type f -exec /some/place/sed.sh {} \;