Operating System - Linux
1828219 Members
1821 Online
109975 Solutions
New Discussion

Inserting a column of text into a file

 
SOLVED
Go to solution
TheJuiceman
Super Advisor

Inserting a column of text into a file

Hey everyone,

What would be the easiest way for me to insert a column of text into the beginning of a file? Basically, I'm wanting to do the following:

cat file:

this is my text
this is line 2
this is line 3

change to:

insert this is my text
insert this is line 2
insert this is line 3

Thanks for the help.
2 REPLIES 2
Hein van den Heuvel
Honored Contributor
Solution

Re: Inserting a column of text into a file

so many solutions...
Most unix folks will probably propose 'sed'.
I just pick awk or perl

awk '{print "insert " $0}' file

or with perl and replace in-place

perl -pie "$_ = "insert " . $_" file

fwiw,
Hein.


TheJuiceman
Super Advisor

Re: Inserting a column of text into a file

Great answer. Thanks a million!!!