LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2007, 12:13 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Copy in VI editor


Hi Guys,


I am working on remotely using putty to my server. I have a file which has
1866778 lines of text. From that i need to copy from 1191715 to 1195161 and paste it in the local computer's textpad.

How can i do it? Please let me know.


Q2. How can i copy the entire text of a file with 1866778 lines (ex:logs) in a remote server to my local computer, where am working on putty?


Thanks in Advance.
 
Old 12-14-2007, 02:05 AM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Quote:
Originally Posted by ZAMO View Post
Hi Guys,


I am working on remotely using putty to my server. I have a file which has
1866778 lines of text. From that i need to copy from 1191715 to 1195161 and paste it in the local computer's textpad.

How can i do it? Please let me know.


Q2. How can i copy the entire text of a file with 1866778 lines (ex:logs) in a remote server to my local computer, where am working on putty?


Thanks in Advance.
Open your favorite editor, which is definitely VIM
Set the line numbers on by typing
:se nu
Go to the correct line by typing
:1191715
Press V for using visual mode. Now you can move your cursor until the line you want.
Then press Y to copy the lines.
Open the target file by typing
:sv targetfile
and press P in it.
Now save and exit by typing
:wq


You can copy the file by using scp.
scp user@remote-host:/path/to/file /local/destination

DONE
 
Old 12-14-2007, 02:13 AM   #3
antis
Member
 
Registered: Nov 2004
Location: sweden
Distribution: Arch
Posts: 67

Rep: Reputation: 15
The easiest way is probably to do something like this:

Code:
head -n 1195161 yourfile.txt | tail -n 3446 > tempfile.txt
...and then copy the file to your local computer with scp/ftp.
 
Old 12-14-2007, 02:21 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
vi file
:191715,1195161 wq! newfile

You can even pass this in using echo:

Code:
echo ":191715,1195161 wq! newfile" | vi file

Last edited by Disillusionist; 12-14-2007 at 02:24 AM.
 
Old 12-14-2007, 02:26 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Great guys.

i did it. I need to study a lot.
thank you again for the timely help of both
 
Old 12-19-2007, 11:48 AM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Actually don't use a head/tail pipe to extract from the middle of a file, use sed instead:
Code:
sed -n  '1191715,1195161p'  source_file  > output_file
That way you can use absolute line #'s in the command.


Code:
head -n 1195161 yourfile.txt | tail -n 3446 > tempfile.txt
is really:
Code:
FIRST=1191715
LAST=1195161
head -n $LAST yourfile.txt  | tail -n $(($LAST-$FIRST+1))  > tempfile.txt
if "from 1191715 to 1195161" is meant to be inclusive.
 
Old 12-19-2007, 12:53 PM   #7
xlq
Member
 
Registered: Feb 2007
Distribution: Slackware 12.0
Posts: 58

Rep: Reputation: 15
1191715ggV1195161y:new
p

1191715gg - go to line 1191715
V - enter visual (selection) mode
1195161gg - go to line 1195161
y - yank selection
:new - open a new buffer
p - paste
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy/paste a line in nano editor smp0219 Linux - Newbie 10 08-06-2019 03:24 PM
How to copy not cut in the nano text editor jxrod2000 Linux - Software 16 06-05-2011 04:21 AM
Which light text editor can copy text from file and paste in browser? davidas Linux - Software 9 03-06-2006 11:28 AM
How can we copy the program code wriiten in notepad to linux vi editor? mayank027 Linux - General 2 10-25-2005 06:14 AM
copy lines in vi editor jkmartha Linux - Newbie 4 05-14-2005 02:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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