LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-17-2006, 08:28 AM   #1
itz2000
Member
 
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, 09:03 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
sed 1,100d file.txt > new_file.txt
 
Old 01-17-2006, 01:29 PM   #3
itz2000
Member
 
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
right?
 
Old 01-17-2006, 03:33 PM   #4
frob23
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.
Code:
sed '1,100d' file.txt > tmpfile.txt && mv tmpfile.txt file.txt

Last edited by frob23; 01-17-2006 at 03:38 PM.
 
Old 01-17-2006, 05:42 PM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Code:
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-17-2006, 11:19 PM   #6
wmakowski
Member
 
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

Bill
 
  


Reply



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 01:35 AM
/home file system 100% full gromo Linux - Enterprise 5 11-04-2004 09:47 PM
RBEM56G-100 Xircom RealPort Cardbus Ethernet 10/100+Model 56 Linux Drivers/ Phalk sxa Linux - Laptop and Netbook 1 06-12-2004 11:20 AM
Over 100 terminal windows open automatically after login kimbergross Linux - Newbie 1 10-01-2003 01:50 AM
ATA 100 or UltraDMA/100...whatever rdaves@earthlink.net Linux - Software 3 09-30-2003 06:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:59 PM.

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