til.duyet.net
blog
Search…
til.duyet.net
🤪
Today I Learned
Data Engineering
☁
AWS
⚒
Tools
💻
Shell
MacOS's Touch ID on Terminal
Using `sed` to find and replace in file
Merging contents of multiple .csv files into single .csv file
☸
Kubernetes, Helm, Kustomize
🔄
Apache Airflow
🐳
Docker
Database
Google BigQuery
Apache Hive
AWS Redshift / Postgres
Presto
Programming
🍪
Rust
🐍
Python
👻
Golang
💎
Javascript / Typescript
✨
FE / React
Unix
Git - Pretty git branch graphs
Checking files in Docker build context
Bash get the directory of the current script
Vim
Find and replace
Miscellaneous
[Fig] Single machine and distributed system structure
Deploying Machine Learning Models at Scale
Bypass a Chrome certificate/HSTS error
Articles
Powered By
GitBook
Using `sed` to find and replace in file
sed = Stream EDitor
sed find and replace text
1
sed 's/word1/word2/g' input.file
Copied!
Find and replace text and save to new file
1
sed 's/word1/word2/g' input.file > output.file
Copied!
Note:
s/
means substitute
/g
means global replace
Can change delimiter
/
to something else:
1
sed 's~word1~word2~g' input.file > output.file
Copied!
Find and replace in the line contains something
1
sed -i -e '/FOO/s/love/sick/' input.txt
Copied!
In this example only find the word
love
and replace it with the
sick
if line content a specific string such as
FOO
Find and replace multiple files in sub-folder
1
find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;
Copied!
-i
to save the temporary file
Source:
https://stackoverflow.com/a/6759339
Previous
MacOS's Touch ID on Terminal
Next
Merging contents of multiple .csv files into single .csv file
Last modified
1yr ago
Copy link
Edit on GitHub
Contents
sed find and replace text
Can change delimiter / to something else:
Find and replace in the line contains something
Find and replace multiple files in sub-folder