command to replace the entire line from the key point

Hi everyone
I am new to Unix. I got stuck up by small issue.

I have text file something like this

abc 'xyz' '5'
lmn 'pqr' '7'

i want to replace the abc 'xyz' '5' to abc 'xyz' '6'

but i have a key as 'xyz' based on this key i want to do that.

I am not aware of how to use sed command.
i tried something like this but no luck.

sed 's/'xyz' '5'/'xyz' '6'/g' filename

but it is going to
>
>
Mode

I don't want script.I want to use this in a single command.
Note :Key should be matched with 'xyz' and should replace entire line.
Please help me. its urgent.

Thanks

In the sed command, quote the single quotes with a reverse solidus.
For example:

sed -e "s/abc \'xyz\' \'5\'/abc \'xyz\' \'6\'/g" filename

The skeleton of this sed is:
sed -e "s/old string/new string/g" filename

The "g" means global i.e. process the whole file.

Hi !

Tanks for your quick reply

I tried but no luck.

It is not replacing the word

sed -e "s/option \'channel\' \'5\'/option \'channel\' \'8\'/g" abc1

This is what my command.

My file is something like this.

config 'wifi-device' 'wifi0'
option 'type' 'atheros'
option 'disabled' '0'
option 'channel' '5'
option 'hwmode' '11b'
option 'diversity' '0'
config 'wifi-iface'
option 'device' 'wifi0'
option 'network' 'lan'
option 'ssid' 'OpenWrt'
option 'mode' 'adhoc'
option 'encryption' 'none'

Thanks

Just tried it by cut/paste from your post and it is working.

Can you post the output from:

sed -n l abc1

In case the field delimiter is a tab or something?

Hi

I tried with

sed -n l abc1

No response.

if it is tab then how do i use sed command.
i mean how do i specify the tab character in sed command.

Thanks

sed -e 's/oldwordname/newwordname/g' filename >newfile
This Command is useful it should work

Hi,

Please use.

sed -e 's/oldwordname/newwordname/g' filename >new_file
mv new_file orignal_file

I think this should work.

Cheers,
Shazin

Hi Shazin

I tried but no luck.
my file is something like this

i know the key 'channel' based on this key i want to rewrite the particular line.how do i do that

config 'wifi-device' 'wifi0'
option 'type' 'atheros'
option 'disabled' '0'
option 'channel' '5'
option 'hwmode' '11b'
option 'diversity' '0'
config 'wifi-iface'
option 'device' 'wifi0'
option 'network' 'lan'
option 'ssid' 'OpenWrt'
option 'mode' 'adhoc'
option 'encryption' 'none'

for example something like this

sed -e "s/'channel'/option 'channel' '6'/g" abc1

i am expecting out as

config 'wifi-device' 'wifi0'
option 'type' 'atheros'
option 'disabled' '0'
option 'channel' '6'
option 'hwmode' '11b'
option 'diversity' '0'
config 'wifi-iface'
option 'device' 'wifi0'
option 'network' 'lan'
option 'ssid' 'OpenWrt'
option 'mode' 'adhoc'
option 'encryption' 'none'

Note : The number changed from '5' to '6' based on the key 'channel'
It should overwrite the same file.