Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-08-2013
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 32
Thanked 1 Time in 1 Post
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

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

Sponsored Links
    #2  
Old 03-08-2013
franzpizzo's Avatar
Registered User
 
Join Date: Feb 2013
Posts: 63
Thanks: 0
Thanked 11 Times in 11 Posts
Sorry, but you really want do this with vi? Why?
If you use sed I can help you.
Let me know.
Sponsored Links
    #3  
Old 03-08-2013
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 32
Thanked 1 Time in 1 Post
Ok. How can I do this with sed or any other utility?
    #4  
Old 03-08-2013
Registered User
 
Join Date: Aug 2006
Posts: 313
Thanks: 1
Thanked 47 Times in 45 Posts
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

The Following User Says Thank You to cero For This Useful Post:
kraljic (03-09-2013)
Sponsored Links
    #5  
Old 03-08-2013
gary_w's Avatar
Registered User
 
Join Date: Oct 2010
Posts: 446
Thanks: 31
Thanked 96 Times in 88 Posts
If sed chokes on it perl may be a better choice.
The Following User Says Thank You to gary_w For This Useful Post:
kraljic (03-09-2013)
Sponsored Links
    #6  
Old 03-08-2013
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Registered User
 
Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,952
Thanks: 6
Thanked 79 Times in 77 Posts
q - Quit the sed script and avoid further processing

Code:
sed -ne '5000,7000{p;7000q;}' /path/to/input >/path/to/output

The Following User Says Thank You to anbu23 For This Useful Post:
kraljic (03-09-2013)
Sponsored Links
    #7  
Old 03-08-2013
Registered User
 
Join Date: Mar 2013
Posts: 858
Thanks: 18
Thanked 179 Times in 176 Posts
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

The Following User Says Thank You to hanson44 For This Useful Post:
kraljic (03-09-2013)
Sponsored Links
Reply

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
Epic Editor was not able to obtain a license for your use. Feature Epic Editor :Licen durgaprasadr13 Solaris 1 10-13-2008 07:39 AM
set EDITOR=vi -> default editor not setting for cron tab aarora_98 Shell Programming and Scripting 6 09-13-2008 02:01 AM
Pasting text in VI editor from a different editor harishmitty UNIX for Dummies Questions & Answers 10 09-10-2008 06:22 PM
instead VI editor - which one? diamond HP-UX 6 07-18-2005 01:43 AM
GUI editor same as vi editor.? abidmalik UNIX for Dummies Questions & Answers 4 09-10-2002 08:53 PM



All times are GMT -4. The time now is 10:22 AM.