![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|