Saturday, June 4, 2022

[SOLVED] Using Sed to delete multiple lines

Issue

I have been using

sed -i '58d' test_file.txt 

to delete a line &

sed -i '58,68d' test_file.txt

to delete multiple lines in a row

but I tried to use

sed -i '58;64;93d' test_file.txt

to delete those 3 specific lines, which was the answer I found, but I get an error that the

; 

character is an unknown command. Any idea on how I can fix this?


Solution

For example you could:

sed -i '2d;5d;8d' file

test with seq:

kent$  seq 10|sed '2d;5d;8d'
1
3
4
6
7
9
10


Answered By - Kent
Answer Checked By - Katrina (WPSolving Volunteer)