Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-17-2006, 09:28 AM   #1
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
deleting 100 rows in text file (1-100) via terminal

deleting 100 rows in text file (1-100) via terminal

how can I do that?
Old 01-17-2006, 10:03 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 60
sed 1,100d file.txt > new_file.txt
Old 01-17-2006, 02:29 PM   #3
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
thanks.... can I though write it to same file?

sed 1,10 file.txt > file.txt
Old 01-17-2006, 04:33 PM   #4
Senior Member
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
No. Do not do that because you will end up with an empty file.

You need to use the temporary file for this because the redirection empties the file before anything happens.

You can use the following to do it in one step. Note: the && means to only execute the mv command if the first command returns without an error.
sed '1,100d' file.txt > tmpfile.txt && mv tmpfile.txt file.txt

Last edited by frob23; 01-17-2006 at 04:38 PM.
Old 01-17-2006, 06:42 PM   #5
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
sed -e '1,100d' -i file.txt
Will make the changes inside the file and avoid the need for the hackish file work done above.
Old 01-18-2006, 12:19 AM   #6
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, RHL 5.2
Posts: 560

Rep: Reputation: 56
If you want to use an editor, vi can do that pretty easily.

1) vi file.txt
2) while on first line of file.txt type 100dd
3) :wq



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Xircom CreditCard 10/100 CE3-10/100 driver not loaded under FEDORA or RHEL androphag Linux - Laptop and Netbook 1 02-06-2005 02:35 AM
/home file system 100% full gromo Linux - Enterprise 5 11-04-2004 10:47 PM
RBEM56G-100 Xircom RealPort Cardbus Ethernet 10/100+Model 56 Linux Drivers/ Phalk sxa Linux - Laptop and Netbook 1 06-12-2004 12:20 PM
Over 100 terminal windows open automatically after login kimbergross Linux - Newbie 1 10-01-2003 02:50 AM
ATA 100 or UltraDMA/100...whatever Linux - Software 3 09-30-2003 07:49 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration