forked from qinshulei/ubuntu-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sed
23 lines (16 loc) · 735 Bytes
/
sed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# To replace all occurrences of "day" with "night" and write to stdout:
sed 's/day/night/g' file.txt
# To replace all occurrences of "day" with "night" within file.txt:
sed -i 's/day/night/g' file.txt
# To replace all occurrences of "day" with "night" on stdin:
echo 'It is daytime' | sed 's/day/night/g'
# To remove leading spaces
sed -i -r 's/^\s+//g' file.txt
# To remove empty lines and print results to stdout:
sed '/^$/d' file.txt
# To replace newlines in multiple lines
sed ':a;N;$!ba;s/\n//g' file.txt
# To replace newlines with \n in multiple lines
sed ':a;N;$!ba;s/\n/\\n/g' file.txt
# replace all file in directory
find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA.example.com/subdomainB.example.com/g'