The UNIX and Linux Forums  
Hello and Welcome from 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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find and Replace NycUnxer UNIX for Dummies Questions & Answers 4 03-06-2008 12:20 AM
find replace dbsurf Shell Programming and Scripting 2 01-25-2008 08:39 AM
find and replace mahabunta UNIX for Dummies Questions & Answers 7 09-21-2006 01:05 PM
find and replace vikas_j@hotmail UNIX for Dummies Questions & Answers 3 02-25-2002 05:41 PM
Find & Replace gagansharma Shell Programming and Scripting 3 11-27-2001 04:17 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-27-2009
allrise123 allrise123 is offline
Registered User
  
 

Join Date: May 2009
Posts: 9
find and replace problem

hi guys!!!

i am writing a script in which i take an input from user and find it in a file and replace it.
My input file looks like
Code:
hi
what your name?
allrise
my code looks is
Code:
echo "Enter the name"
read name
FILE="/opt/name.txt"
NEW_FILE="/opt/new_name.txt"
exec 0<$FILE
    while read line
    do
     if [ -n "`echo ${line} | grep 'allrise'`" ]
     then
              echo ${line} | sed 's|allrise|hello $name|g' >>$NEW_FILE
     else
             echo $line >>$NEW_FILE
     fi
     done <$FILE
When i run my script, it ask me for name suppose i gave "john"... but the output comes as shown below
Code:
hi
what your name?
hello $name
so, can anyone explain how i can get proper output which should be.
Code:
hi
what your name?
hello john
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0