LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices



Reply
 
Search this Thread
Old 07-28-2008, 04:55 AM   #1
soumalya
Member
 
Registered: Nov 2006
Posts: 260

Rep: Reputation: 31
vi editor problem


Sir

is there any solve to delete all the content in a file ?

suppose i want to delete all the content in store.log, which is 3 gb now. is there any single command to delete al the content in store.log using vi editor?



pls help


thanks in advance
 
Old 07-28-2008, 04:58 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
From anyline you're on, to the end of the file

dG
 
Old 07-28-2008, 12:27 PM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,032

Rep: Reputation: 174Reputation: 174
There are much faster and easier ways to delete all the contents of a file than using vi.

Code:
mike@continuity:/tmp$ cat store.log
blah
wah blah
wah
blah
wa
wa
wa
mike@continuity:/tmp$ >store.log
mike@continuity:/tmp$ cat store.log
mike@continuity:/tmp$
 
Old 07-28-2008, 01:15 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Oh, absolutely. Don't even bother trying vim with a 3Gig file! arizonagroovejet has the best solution if you just want to empty the entire file.
 
Old 07-29-2008, 12:33 AM   #5
soumalya
Member
 
Registered: Nov 2006
Posts: 260

Original Poster
Rep: Reputation: 31
thanks for ur reply

can u tell me the command or key to delete all content of a file in vi editor.
 
Old 07-29-2008, 12:35 AM   #6
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
Did you try the suggestion in the very first reply?
 
Old 07-29-2008, 04:21 PM   #7
KasMage
LQ Newbie
 
Registered: Jul 2008
Location: Indiana
Distribution: Mandriva 2008.1
Posts: 21

Rep: Reputation: 15
I can't test this at my current location, but I think that this will work as well:

d%

That would actually delete the entire file's contents. dG is just as good, except you'd need to start from line 1 to get it to remove the whole thing. Then of course there is the "> filename" suggestion. All of those ways would work fine (assuming I'm right about d%).

EDIT : The following is the correct method:

:%d

Thanks, Mr. C.!

Last edited by KasMage; 07-30-2008 at 09:22 AM. Reason: Edited in corrected operation
 
Old 07-29-2008, 04:27 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
No, % means 1,$ in Ex mode, not within vi mode. The d operator takes a motion, and % is not a motion but a range.

Use
:%d
instead.

Last edited by Mr. C.; 07-29-2008 at 04:31 PM.
 
Old 07-30-2008, 09:05 AM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Alternately, at the cmd line:

rm store.log
touch store.log
 
Old 07-30-2008, 09:29 AM   #10
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,032

Rep: Reputation: 174Reputation: 174
Quote:
Originally Posted by chrism01 View Post
Alternately, at the cmd line:

rm store.log
touch store.log
True, but that's a lot more typing that the non-vi solution I already posted.
 
Old 08-04-2008, 12:46 AM   #11
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 302
Blog Entries: 1

Rep: Reputation: 34
if its a single paragraph use
dd
 
Old 08-12-2008, 01:15 AM   #12
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
He's talking about cleaning out a 3GB file (see OP). I still think doing it at the cmd line makes more sense. No need to go into an editor. Remember vi/vim makes a temp backup while the file is open...


@geniushasan:
Incidentally, 'dd' only deletes 1 line.

Last edited by chrism01; 08-12-2008 at 01:16 AM.
 
  


Reply


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
vi editor problem sajith Programming 6 08-18-2014 08:46 AM
menue editor problem Hushang Linux - Desktop 1 04-04-2007 01:52 PM
Problem in vi editor init_linux Linux - General 10 09-09-2005 02:40 AM
problem with Vi Editor sailu_mvn Linux - Software 1 08-09-2005 08:27 AM
Problem with the EDITOR variable objorkum Slackware 2 10-19-2004 04:29 PM


All times are GMT -5. The time now is 06:09 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration