The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-09-2008
kartikkumar84@g kartikkumar84@g is offline
Registered User
 

Join Date: May 2008
Posts: 16
How to insert text in the middle of a file w/o SED or AWK!!

tht dint wrk as i am trying to do this using a script..im pasting the script

#!bin/bash

echo "Enter a line of text";
read text;

echo "Enter the file path to append to";
read path;

nfline=$(wc -l $path);
middle=$($nfline/2);


head -$middle $path > tmpfile;
$text >> tmpfile;
tail -$middle $path >> tmpfile;

mv tmpfile $path;

more $path;

Last edited by kartikkumar84@g; 05-09-2008 at 06:06 PM.
Reply With Quote