LinuxQuestions.org
Help answer threads with 0 replies.
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 10-25-2007, 04:05 AM   #1
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
vi - jumping to the end of text


hi everybody..

i am using VI editor to read(&edit) some huge log files. I need to scroll down to the end of the file, but it is like 100000 lines. Is there a short cut for this?
 
Old 10-25-2007, 04:06 AM   #2
christianunix
Member
 
Registered: Oct 2007
Posts: 40

Rep: Reputation: 15
if the name of the file is mylog

then use this command at the command line

Code:
tail mylog
or if you want to view the last 15 lines,

then

Code:
tail -15 mylog
if you want to edit the file then for example last 30 lines

Code:
wc -l mylog
the above will give you the number of lines

then

let's say there are 10,000 lines

then do some simple math and you will only have to edit the last 30 lines.

and then,

Code:
head -9970 mylog  > upperfile;tail -30 mylog > lowerfile;pico lowerfile
will open the pico editor and let you edit the last 30 lines of the file

and then

when you are finished with editing the file with the pico editor(who uses vi editor nowadays?) save and exit by pressing ctrl x

then at the commandline

Code:
cat upperfile lowerfile > mylog
will give you a new mylog with the last 30 lines modified to your taste and needs.

Last edited by christianunix; 10-25-2007 at 04:14 AM.
 
Old 10-25-2007, 04:11 AM   #3
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124

Original Poster
Blog Entries: 2

Rep: Reputation: 15
thanks lot..
but not i can not edit is it right?
does Vi not have such function?
 
Old 10-25-2007, 04:14 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I don't remember of any shortcut to jump to the end of file (this does not mean it does not exist, anyway). However you can do Ctrl-G to visualize the number of lines and then jump to the last line with :nnn, where nnn is the number of lines above. You can also consider Ctrl-F and Ctrl-B to jump forward and back by one page, respectively.
 
Old 10-25-2007, 04:18 AM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Just typing G (uppercase g) will take you to the last line in a file.
 
Old 10-25-2007, 04:20 AM   #6
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124

Original Poster
Blog Entries: 2

Rep: Reputation: 15
Quote:
Originally Posted by pwc101 View Post
Just typing G (uppercase g) will take you to the last line in a file.
bingo!! thx a lot
 
Old 10-25-2007, 04:31 AM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
No problem
 
Old 10-25-2007, 04:58 AM   #8
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
'G' is what I use too. ':$' also works, which is worth a mention because you can use it within a regex (or any other Vi operation). e.g. :5,$d to delete everything from line 5 to end-of-file.
 
  


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
Deleting empty line at end of text file in BASH human2.0 Linux - General 8 04-01-2009 02:44 AM
LXer: Lenovo embeds Linux in high-end and low-end notebooks LXer Syndicated Linux News 0 08-10-2006 11:21 AM
Text curner keeps jumping? idgeitman Linux - Laptop and Netbook 4 04-21-2006 05:30 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM
Rich Text Widget/Database Front End Stranger Programming 5 10-03-2004 06:37 PM

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

All times are GMT -5. The time now is 09:40 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