Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete a line in a file from command prompt 1

Status
Not open for further replies.

ozi403

Technical User
Apr 29, 2002
54
0
0
TR
How can I delete a line in a file from command prompt?
 
man sed

sed 'Xn' file.txt

where X is the line number.

Cheers.

Chacal, Inc.
 
BTW, redirect the output to another file:

sed '10d' file.txt > output.txt

Cheers,

Chacal, Inc.
 
with ed you can edit the file in place, no need for another file (other than the temp copy ed will make for itself)

delete line number 10 from file.txt from command line with an inline input document:
ed file.txt <<eof_ed
10d
w
q
eof_ed

or a one-liner:
echo "10d\nw\nq"|ed file.txt

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top