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"
}

> 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"

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

Best wishes,

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.