For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2006 > Inserting lines at top and bottom of file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Inserting lines at top and bottom of file
eldiabloinfernal

2006-01-13, 6:56 pm

hi gurus,

I have the following problem.

I have a file and would like to insert a line of text at the top and a
line of text at the bottom.

eg:


-----top of file -----------

<insert start line here>
abcd
defg
hijk
lmno
<insert end line here>

-----e bottom of file ----------


Is there a quick way of doing this ? I currently use cat (file1 file2
file3) > filex but it is not very fast and efficient. I would like to
use a method which uses little resource and is fast.

many thanks in advance

dean

Ed Morton

2006-01-13, 6:56 pm



eldiabloinfernal wrote:
> hi gurus,
>
> I have the following problem.
>
> I have a file and would like to insert a line of text at the top and a
> line of text at the bottom.
>
> eg:
>
>
> -----top of file -----------
>
> <insert start line here>
> abcd
> defg
> hijk
> lmno
> <insert end line here>
>
> -----e bottom of file ----------
>
>
> Is there a quick way of doing this ? I currently use cat (file1 file2
> file3) > filex but it is not very fast and efficient. I would like to
> use a method which uses little resource and is fast.
>
> many thanks in advance
>
> dean


awk 'BEGIN{print "start"}1;END{print "end"}' file

<OT>
This would probably be faster if you use UNIX shell:

echo "start"; cat file; echo "end"

Follow up at comp.unix.shell if you don't specifically need an awk solution
</OT>

Regards,

Ed.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com