Computing.Net > Forums > Unix > vi : insert a string every 2nd line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vi : insert a string every 2nd line

Reply to Message Icon

Name: ted08
Date: November 18, 2008 at 07:41:23 Pacific
OS: solaris 5.10
CPU/Ram: 4 core 32G
Product: T2000
Comment:

Hi,

I have a file in vi which looks something like this:

get_date
update_date
delete_date
new_time
get_amount
update_amount

I want to insert a new line with a string, every second line, such that the file will look like:


get_date
go
update_date
go
delete_date
go
new_time
go
get_amount
go
update_amount
go

The recurring pattern in the file is the "-"
So could use that in a pattern match/search

Thanks in advance,

Ted08



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 18, 2008 at 13:44:48 Pacific
Reply:

Why do you need vi? Simply use the modulo operator in something like awk:

#!/bin/ksh

awk ' {
print $0
if(NR % 1 == 0 )
print "go"
} ' datafile.txt


0

Response Number 2
Name: ted08
Date: November 19, 2008 at 04:06:19 Pacific
Reply:

Thats just what I'm after. Thanks nails


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: vi : insert a string every 2nd line

How to insert string in a list? www.computing.net/answers/unix/how-to-insert-string-in-a-list/7138.html

Inserting a string at the end of a www.computing.net/answers/unix/inserting-a-string-at-the-end-of-a-/6205.html

insert a delimeter in a text www.computing.net/answers/unix/insert-a-delimeter-in-a-text/7677.html