Linux sed

Cli

Basic usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# print first 30 lines
sed 1,30d log.log

# delete first 30 lines
sed -e 1,30d log.log

# delete 17th lines
sed -e 17d log.log

# delete last 20 lines
sed -e '10,$d' log.log


# delete last 20 lines and backup file that named 'log.log.bak'
sed -e '10,$d' -i '.bak' log.log


# replace StdOut
sed -e 's/__variable__/__replaced__/g' file.txt

# replace in file
sed -e's/__variable__/__replaced__/g' -i '' file.txt

Reference

https://linux.die.net/man/1/sed