Skip to content

fasiddique/shell-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

shell-scripts

Description

Multiple shell scripts!

Usage

find-and-replace.sh

⚠️ Be very careful while using it! This script overrides the original file! There is no way you can revert.

What it does?

Find some texts in a file and replace it with provided texts. But the power of the script does not lie within the find and replace task! If you have say 10k txt files in a directory and you want to check if the files contain the text "worries" and replace it with "hakuna matata". You are not obviously going to manually check all 10k files! Instead use this script and it will do the job for you!

How it works?
  1. Iterate over all the files with the given extension in present working directory.
for f in *.txt ; do
  1. Print out the current file name it's investigating on.
echo "Processing $f..."
  1. Finds the word vasim in the file $f, and replace it with the filename except the extension.
sed -i "s/vasim/$(basename -- "$f" .txt)/g" $f

Releases

No releases published

Packages

No packages published

Languages