Inserting specific lines in vi

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Inserting specific lines in vi
# 1  
Old 04-29-2002
Inserting specific lines in vi

How can I insert, say lines 500 - 700 from another file into the current file on the current line (cursor) that I am editing while in vi (AIX).

I know how to insert the entire file but how do you do it when you only need certain lines from a huge file?

I've referenced my Unix Unleash book but it doesn't say...

# 2  
Old 04-29-2002
:r !sed -n '500,700p' < anotherfile

But I rarely happen to know that I need exactly those lines. What I do is first "vi insert", read in the other file, delete what I don't want, then edit the real file and read in insert.
# 3  
Old 05-01-2002
here's another solution, but you'll need a vi-clone that
supports multiple 'windows' (e.g Vim, Elvis etc..):

$ vi currentfile

:split anotherfile

highlight lines 500 - 700

Insert lines in current file
Move down to the other file (^wj) and press:

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

2. UNIX for Advanced & Expert Users

Inserting delimiter after a specific number of chars

Hello guys, I have a problem where I need to add a delimiter, that can be | for example, after each 28000 chars. The problem is that sometimes 1 row, which should contain 28000 chars is split in 2, so I want to put the delimiter after each 28000 so I will know the end of each row. Please... (2 Replies)
Discussion started by: Diogo R Jesus
2 Replies

3. Shell Programming and Scripting

Inserting comma after a specific pattern

Hi Am using ksh shell I have a file like XYSDHY read write; permission; complete; DEGHLO RTERI dersa; upomxi oidewmiew; jdipowj;Now i need to insert semicolon after the BLOCK LETTER patterns and delete all blank lines. Now I need the output as XYSDHY; read write; permission;... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

inserting and replacing lines with awk

Hello, I need to insert varying lines (i.e. these lines are an output of another script) between lines starting with certain fields. An example to make it more clear. This is the file where I wanna insert lines: (save it as "input.txt") ContrInMi_c_mir 2 10066 181014 200750... (12 Replies)
Discussion started by: tempestas
12 Replies

5. Shell Programming and Scripting

inserting multiple lines with awk

awk '/<login-module code="" flag="sufficient">/{p++} /<login-module code="" flag="sufficient">/ && p==1 {$0="Mulitple lines here\n"$0}1' login-config.xml In the above awk code inside shell script, i am having problems when... (1 Reply)
Discussion started by: sunrexstar
1 Replies

6. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

7. Shell Programming and Scripting

inserting lines

Hi I would like to add lines to a file at specific locations. eg: If I have a file containing data... ABC DEF GHIJKLKMNOP RSTUVWXYZ and I have a requirement to insert a lines a) "LINE_FIRST" before first line in the file b) "LINE_X" before third line in the file c) "LINE_LAST"... (2 Replies)
Discussion started by: tostay2003
2 Replies

8. Shell Programming and Scripting

Problem inserting text into file after specific line

this is utterly embarassing :( after posting here i revisited my files and found that when i used "vi" instead of a gui based editor, i suddenly found that the indentations were in fact wrong :( sorry about this :( (0 Replies)
Discussion started by: mocca
0 Replies

9. Shell Programming and Scripting

Inserting lines in between the contents of file.

Hi, I want to insert some lines in between the contents of a file but the file format should not be changed. #!/usr/bin/sh - # Link appropriate OS specific versions of vxicap and vxchk4badblks vxlvmlink() { vxipath=/usr/lib/vxvm/bin relmajor=`uname -v` ... (1 Reply)
Discussion started by: ajilesh
1 Replies

10. Shell Programming and Scripting

inserting a lines in a file

Hi folks, i need to insert the same set of lines between each line input lines 111111 aaaaaa 333333 output should be 111111 1 2 3 aaaaaa 1 2 3 333333 1 (2 Replies)
Discussion started by: Balaji Sukumara
2 Replies
Login or Register to Ask a Question