How can I do this in VI editor?

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 03-08-2013
How can I do this in VI editor?

version info :
vi availabe with RHEL 5.4
I have a text file with 10,000 lines. I want to copy lines from 5000th line to 7000th and redirect to a file. Any idea how I can do this?

Note:
The above scenario is just an example. In my actual requirement, the file has 14 million lines and I want to copy 2000 lines after the 12th million line Smilie

BTW.I've just realised that the vi editor we use in RHEL is actually VIM
Code:
 
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
$
$ which vi
/bin/vi

# 2  
Old 03-08-2013
Sorry, but you really want do this with vi? Why?
If you use sed I can help you.
Let me know.
# 3  
Old 03-08-2013
Ok. How can I do this with sed or any other utility?
# 4  
Old 03-08-2013
Not sure how sed will react on a 14 million line file but 10k lines should be no problem:
Code:
sed -ne '5000,7000p' /path/to/input >/path/to/output

This User Gave Thanks to cero For This Post:
kraljic (03-09-2013)
# 5  
Old 03-08-2013
If sed chokes on it perl may be a better choice.
This User Gave Thanks to gary_w For This Post:
kraljic (03-09-2013)
# 6  
Old 03-08-2013
q - Quit the sed script and avoid further processing
Code:
sed -ne '5000,7000{p;7000q;}' /path/to/input >/path/to/output

This User Gave Thanks to anbu23 For This Post:
kraljic (03-09-2013)
# 7  
Old 03-09-2013
sed would never choke on this task, no matter how many lines. Even billions of lines. sed just reads one line at a time, so the number of lines is totally not an issue. If I'm wrong about this, I'd like to be educated.

Here is similar (but tad simpler) solution to previous valid solution posted:
Code:
sed -n "5000,7000 p; 7000 q" infile

This User Gave Thanks to hanson44 For This Post:
kraljic (03-09-2013)

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
What editor does everyone use? yongho Open Source 401 5 Days Ago 05:58 AM
Help with vi editor gonchusirsa UNIX for Dummies Questions & Answers 1 01-19-2013 12:55 AM
Vi Editor Sudip_Felipemas UNIX for Dummies Questions & Answers 6 02-02-2012 08:01 AM
Help in Vi Editor gameboy87 Programming 2 09-16-2011 11:05 PM
Vi editor jazz Programming 2 05-08-2009 09:46 AM
Epic Editor was not able to obtain a license for your use. Feature Epic Editor :Licen durgaprasadr13 Solaris 1 10-13-2008 08:39 AM
set EDITOR=vi -> default editor not setting for cron tab aarora_98 Shell Programming and Scripting 6 09-13-2008 03:01 AM
Pasting text in VI editor from a different editor harishmitty UNIX for Dummies Questions & Answers 10 09-10-2008 07:22 PM
VI Editor doyindayo UNIX and Linux Applications 3 08-26-2008 09:14 AM
Which editor to use? Nafanja UNIX for Dummies Questions & Answers 5 11-29-2007 12:58 PM
vi editor MaxK UNIX for Dummies Questions & Answers 2 10-18-2006 11:42 PM
vi editor diptiman Solaris 15 05-21-2006 12:55 PM
best editor annemar UNIX Desktop Questions & Answers 1 10-10-2005 01:05 PM
vi editor alain123456 UNIX for Advanced & Expert Users 3 07-21-2005 12:07 PM
Vi editor ? billy5 Shell Programming and Scripting 2 06-27-2005 05:20 PM