The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-04-2008
maxmave maxmave is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 21
Replacing a line in a file - HELP!!!

I have a problem in the following code ...

Code:
while read line
do
   #Get Line Number 
   OLDLINE=`sed -n $Lineno $filename`
   echo "Un Changed Line : "$OLDLINE
   echo "Enter a New Pattern : "
   read NewPattern <&1
   echo "NewPattern :"$NewPattern 
   NEWLINE=`cat $filename | sed -n $Lineno | sed s/$OldPattern/$NewPattern/`
   echo $NEWLINE
   LINECHANGE=`sed s/$OLDLINE/$NEWLINE/ $filename`
   echo $LINECHANGE
   ChangedLine=`sed -n $Lineno $filename`
   echo "Changed Line : "$ChangedLine
done < $INT_FILE
I am trying to read a line from a file and get the line and change a pattern in the line and i want to replace the
OLD line with the NEW line.

I have problem in the following line
Code:
LINECHANGE=`sed s/$OLDLINE/$NEWLINE/ $filename`
the OLD Line is not changed in NEW Line in the file.

is there any problem with the command i gave or should i need to correct it

Can anyone please help.


Thanks

Rahul

Last edited by Yogesh Sawant; 06-05-2008 at 01:06 AM.. Reason: added code tags