Visit Our UNIX and Linux User Community

command to replace the entire line from the key point

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users command to replace the entire line from the key point
# 1  
Old 08-30-2009
Question 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

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.

# 2  
Old 08-30-2009
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.

# 3  
Old 09-01-2009
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'

# 4  
Old 09-01-2009
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?
# 5  
Old 09-04-2009

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.

# 6  
Old 09-04-2009
sed -e 's/oldwordname/newwordname/g' filename >newfile
This Command is useful it should work
# 7  
Old 09-04-2009

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

I think this should work.


Previous Thread | Next Thread
Test Your Knowledge in Computers #26
Difficulty: Easy
IPv6 addresses are 256 bits in length.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with sed to replace entire line

Hi, I need to replace an entire mailx line as follows using sed: sed -e 's/<line1>/<newline>/g' <filename> But I am getting comman garbled error since the new line has many special characters. I enclosed allspecial chars in \ but still no use. Can any one help me? Please use code... (2 Replies)
Discussion started by: vinodhin4
2 Replies

2. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Specify an entire UNIX command as a command line argument

I'm trying to write a bash script called YN that looks like the following YN "Specify a question" "doThis" "doThat" where "doThis" will be executed if the answer is "y", otherwise "doThat". For example YN "Do you want to list the file dog?" "ls -al dog" "" Here's my attempt... (3 Replies)
Discussion started by: LeoKSimon
3 Replies

4. Shell Programming and Scripting

up down arrow key and edit on command line.

I am using ksh, By doing change in .profile as set -o vi my updown and history does not work. Also I can not edit command line on prompt using vi command. My TERM is vt100. What is wrong here ? Thanks. :cool: (3 Replies)
Discussion started by: ekb
3 Replies

5. Shell Programming and Scripting

New process, forgot the key point

i am using a newprocess, but i forgot the key point Changed subject. See post below from Neo (2 Replies)
Discussion started by: Maryeveryday
2 Replies

6. Shell Programming and Scripting

Replace entire line

I want to replace one line from my configuration file with the new settings. The file Name: /etc/httpd/conf/httpd.conf The following line should be replaced with the line mentioned below. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "\"%h\"... (3 Replies)
Discussion started by: shantanuo
3 Replies

7. Shell Programming and Scripting

Replace Entire line if any part matches regexp

Hey guys, I have a file that I've slowly been awking, seding, and greping for data entry. I am down to pull the addresses out to insert them into an excel file. Each address is a few lines, but i want to put a semicolon delimiter in between each address so I can export the text file into excel and... (6 Replies)
Discussion started by: Cocoabean
6 Replies

8. Shell Programming and Scripting

Perl Search and replace entire line

I have a perl function in my script that needs to replace an entire line in a file sub changestate { my $base = (); my @base = (); open(BASE, $file) || die("Could not open file!"); @base=<BASE>; close (BASE); foreach $base(@base) { if($base =~... (1 Reply)
Discussion started by: insania
1 Replies

9. Shell Programming and Scripting

Capture entire line in ps command

I need to determine what processes are running at certain times of the day. I have a script that issues the /usr/ucb/ps aux command and captures it to a file. I want to see the cpu usage and memory usage. This command lops off the end of the of the display line so I can't see the entire... (2 Replies)
Discussion started by: MizzGail
2 Replies

10. UNIX for Dummies Questions & Answers

Using the Esc key to complete command line typing

Dear Techs, In the past on a different box (HP) I use to be able to complete something I was typing by entering a portion of the filename in the pwd and I would hit the Esc key and it would match the rest of the filename. I did this without understanding how it was setup. Now I am on a new... (1 Reply)
Discussion started by: jxh461
1 Replies

Featured Tech Videos