|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Sorry, but you really want do this with vi? Why?
If you use sed I can help you. Let me know. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Ok. How can I do this with sed or any other utility?
|
|
#4
|
|||
|
|||
|
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 | |
|
|
#6
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|