How can I do this in VI editor? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

How can I do this in VI editor?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-08-2013
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
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
franzpizzo franzpizzo is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 6 February 2014, 9:56 AM EST
Posts: 68
Thanks: 0
Thanked 12 Times in 12 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
kraljic kraljic is offline
Registered User
 
Join Date: Oct 2011
Last Activity: 7 July 2014, 1:30 AM EDT
Posts: 69
Thanks: 64
Thanked 1 Time in 1 Post
Ok. How can I do this with sed or any other utility?
    #4  
Old 03-08-2013
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 23 July 2014, 8:37 AM EDT
Posts: 361
Thanks: 3
Thanked 64 Times in 59 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
gary_w gary_w is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 10 April 2014, 2:21 PM EDT
Posts: 446
Thanks: 32
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  
Advisor
 
Join Date: Mar 2006
Last Activity: 20 May 2014, 5:16 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 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
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 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
Closed Thread

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 06:11 PM.