Can't find the mistake in sed expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't find the mistake in sed expression
# 1  
Old 02-16-2009
Question Can't find the mistake in sed expression

Hi there,
Can anyone help me find the correct expression for sed.
I want to repace iface eth0 inet wathever
with iface eth0 inet static

Quote:
deneb:~# sed '/^iface eth0 inet (.*)/ s/\1/static/' /etc/network/interfaces
sed: -e expression #1, char 36: Invalid back reference
deneb:~# sed -r '/^iface eth0 inet (.*)/ s/\1/static/' /etc/network/interfaces
sed: -e expression #1, char 36: Invalid back reference
deneb:~# sed '/^iface eth0 inet \(.*\)/ s/\1/static/' /etc/network/interfaces
sed: -e expression #1, char 38: Invalid back reference
deneb:~# sed -r '/^iface eth0 inet \(.*\)/ s/\1/static/' /etc/network/interfaces
sed: -e expression #1, char 38: Invalid back reference
Thanks for your help
Santiago
# 2  
Old 02-16-2009
Try:

Code:
sed 's/\(iface eth0 inet\).*/\1 static/'

Regards
# 3  
Old 02-16-2009
Code:
sed '/^iface eth0 inet / s/^\(iface eth0 inet\).*/\1 static/' /etc/network/interfaces

A back reference is always only valid within the substitution and can't be kept across commands.
# 4  
Old 02-16-2009
Code:
sed '/iface eth0 inet/s/\(.*\) .*$/\1 static/' file

# 5  
Old 02-16-2009
Code:
$ echo 'iface eth0 inet wathever foo' | sed '/^iface eth0 inet / s/^\(iface eth0 inet\).*/\1 static/'
iface eth0 inet static

Code:
$ echo 'iface eth0 inet wathever foo' | sed '/^iface eth0 inet / s/^\(iface eth0 inet\) *\([^ ][^ ]*\) *\(.*\)/\1 static \3/'
iface eth0 inet static foo

# 6  
Old 02-16-2009
Thanks Franklin52, pludi, danmero and vgersh99.
pludi is right when he says:
Quote:
Originally Posted by pludi
[code]A back reference is always only valid within the substitution and can't be kept across commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find a value from an expression?

I have below expression from which I would like to output +m= value: "ginger bread.k +log ../output1 -format +m=3 0 +sleep 10 +suspend 10" The output value should be "3" Any suggestions? (2 Replies)
Discussion started by: bskumarb4u
2 Replies

2. Shell Programming and Scripting

sed regular expression

Hi , I need to remove pipe character from a |^ delimeted file. Something like |^tran|sformers||^|revenge |of fallen|^ to |^transformers|^revenge of fallen|^... Cold anybody please help to build the regular expression using sed . many thanks. Please use code tags next time for... (1 Reply)
Discussion started by: kokjek
1 Replies

3. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

4. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

5. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

6. Shell Programming and Scripting

Can anyone find the mistake in this script file

#!/bin/ksh db_user=`echo $DB_USER_NAME` db_pwd=`echo $DB_PASSWORD` db_sid=`echo $TWO_TASK` sqlplus -s $db_user/$db_pwd@$db_sid << EOF a = select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and bus_event_seq_nbr='3969094' set -- echo $a |... (17 Replies)
Discussion started by: rkrish
17 Replies

7. Shell Programming and Scripting

Find, regular expression, anyway to simplify this find command?

Hello everyone, first post here, trying to learn scripting on my own and this forum as been really helpful so far. I made few little scripts working great but I m facing some problems with RE. I have a bunch of files in many subdirectories called *001.ext *002.ext OR simple *.ext or *01.ext... (7 Replies)
Discussion started by: Sekullos
7 Replies

8. Shell Programming and Scripting

Do not find the mistake in a small routine!!!

Have a textfile (regular updated) with informations about datafiles . Each line is describing a datafile. Now I am trying to delete several specific lines in this textfile, which are defined before in a kind of removal list. Can not find the mistake I have done in the script because in the... (5 Replies)
Discussion started by: jurgen
5 Replies

9. Shell Programming and Scripting

Dont what this sed expression does

I am new to unix and have come across the sed expression but not sure what its doing. Can someone please tell me whats happening in the sed command below? (2 Replies)
Discussion started by: 5211171
2 Replies
Login or Register to Ask a Question