Babak K. Shandiz
Babak K. Shandiz's Blog

Babak K. Shandiz's Blog

Living in the Shell #14; sed (Text Stream Editor) (Part 1)

Living in the Shell #14; sed (Text Stream Editor) (Part 1)

Babak K. Shandiz's photo
Babak K. Shandiz
ยทDec 13, 2021ยท

1 min read

sed ๐Ÿ–Š๏ธ

Edits streams by applying commonly used modifications.

Add a new line a & i

cat some-file.txt | sed '3a This is a new line after the 3rd line' 
cat some-file.txt | sed '3i This is a new line before the 3rd line'

Append a new line to the end $a

cat some-file.txt | sed '$a Now, this is the last line'

Prepend a new line to the beginning 1i

cat some-file.txt | sed '1i Now, this is the first line'

Replace one or more lines c

cat some-file.txt | sed '1-3c BOOM'

Replaces lines 1 through 3, with 'BOOM'.

Delete one or more lines d

cat some-file.txt | sed '1-3d'

Deletes lines 1 through 3.

ย 
Share this