0

ok what i need to do is to make a script function which allows me to change the records in a file. I read some other posts about using sed but i still could not get it to work. The function runs But nothing changes in my file.

This is what my file contains:
Name, Dept, Job, Pay
Jack,FinanceDept,Accountant,$1000

and my code:

function editInfo
{
clear
read -p "Enter current info to edit: " oldInfo
read -p "Enter new info: " newInfo
sed -i 's/oldInfo/newInfo/g' "$dataFile"
}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by eggi
1

> sed -i 's/oldInfo/newInfo/g' "$dataFile"
You need to watch your shell's quoting rules.
Things in single quotes are preserved as is
Things in double quotes allow $substitutions.

Perhaps then
sed -i "s/$oldInfo/$newInfo/g" "$dataFile"

0

Also, as Salem pointed out, don't forget to use the preceding $ character when you're extracting values from your variables.

Best wishes,

Mike

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.