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

itz2000 01-17-2006 09:28 AM

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?

homey 01-17-2006 10:03 AM

sed 1,100d file.txt > new_file.txt

itz2000 01-17-2006 02:29 PM

thanks.... can I though write it to same file?

sed 1,10 file.txt > file.txt

frob23 01-17-2006 04:33 PM

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

cs-cam 01-17-2006 06:42 PM


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.

wmakowski 01-18-2006 12:19 AM

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


All times are GMT -5. The time now is 06:38 AM.