Re: [SLUG] Insert line in a file

From: Eben King (
Date: Thu Sep 18 2003 - 16:01:59 EDT

On Thu, 18 Sep 2003, Rock wrote:

> How can I insert a line in a file at line number 20? Simply please. I
> really understand the straight forward explanations. My mind is just
> wired funny I guess. I am using all shell commands to do this file
> manipulation.

{ head -19 $file ; echo "$line" ; tail +20 $file ; } > $tempfile
mv $tempfile $file

I'm sure there's a nifty way using a sed command, something like

sed -e 1,20p -e c\
-e '21-$p' $file > $tempfile
mv $tempfile $file

but I'm almost sure I've messed that up.

-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm
ARIES:  The look on your face will be priceless when you find that 40lb
watermelon in your colon.  Trade toothbrushes with an albino dwarf, then
give a hickey to Meryl Streep.  -- Weird Al, _Your Horoscope for Today_

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.

This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:40:49 EDT