Skip to content
cheatsheet
home
/
cv
/
weblog
/
cheatsheet
/
proxy
/
vpn
/
status
/
links
EN
RU
☾
New version available
reload
×
cheatsheet
/
sed
/
Extract value from key=value file
Extract value from key=value file
sed
Print the value of DB_HOST from a .env file
sed -n 's/^DB_HOST=//p' .env
⎘ copy
#sed
#linux
more sed
all 15 commands →
Substitute first match per line
sed 's/foo/bar/' file.txt
Substitute all matches (global)
sed 's/foo/bar/g' file.txt
In-place edit
sed -i 's/old/new/g' config.cfg
In-place edit with backup
sed -i.bak 's/old/new/g' file.txt
Delete matching lines
sed '/^#/d' config.txt