delete all lines in file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

delete all lines in file

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-10-2002
strok
Guest
 
Posts: n/a
delete all lines in file

how can i delete all lines in file by using "vi" ?
Sponsored Links
    #2  
Old 03-11-2002
informshilpa informshilpa is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 19 September 2002, 3:18 AM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
You can use following in escape mode to delete all lines from a file.

:1,$d
Sponsored Links
    #3  
Old 03-11-2002
sbw1 sbw1 is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 13 March 2002, 7:40 AM EST
Location: Tampa
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Or, you could enter on line one:

dG

and that would delete to the end of the file.
    #4  
Old 03-11-2002
thehoghunter
Guest
 
Posts: n/a
If you want to delete ALL the lines, don't bother with vi.

$ cat /dev/null > /tmp/the-file-I-want-nothing-in.txt

This will keep you out of vi and delete all the lines.
Sponsored Links
    #5  
Old 03-11-2002
sbw1 sbw1 is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 13 March 2002, 7:40 AM EST
Location: Tampa
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
...Or if you're using ksh, the command

> /tmp/the-file-I-want-nothing-in.txt

will create a null file.
Sponsored Links
    #6  
Old 03-11-2002
mikek147 mikek147 is offline
Registered User
 
Join Date: Feb 2002
Last Activity: 29 April 2004, 3:13 PM EDT
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
touch a_new_empty_file.txt

will create a null file, or will change the last_access_time on that file.

> the_file_I_want_nothing_in.txt

will both empty a full file or create a null file. -mk
Sponsored Links
    #7  
Old 03-11-2002
comadreja comadreja is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 27 June 2003, 4:13 PM EDT
Location: Buenos Aires, Argentina
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
$ echo > file
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
In a huge file, Delete duplicate lines leaving unique lines krishnix UNIX for Advanced & Expert Users 16 08-04-2011 04:47 AM
Delete some lines in a file ponmuthu UNIX for Advanced & Expert Users 5 07-28-2010 02:39 PM
How get only required lines & delete the rest of the lines in file reva UNIX for Dummies Questions & Answers 7 06-01-2010 02:58 AM
How to delete lines in a file that have duplicates or derive the lines that aper once necroman08 Shell Programming and Scripting 3 07-17-2009 05:07 AM
delete first 100 lines from a file salaathi Solaris 7 06-09-2009 10:10 PM



All times are GMT -4. The time now is 12:45 PM.