Sed Help
Tweet
#1
Posted 08 April 2009 - 09:31 PM
it needs to find the first instance of a line and append a line after it
function writeline()
{
ADDLINE="\<rdp_server client_audio=\"$AUDIO\"\ color_depth=\"$COLOR\"\ comment=\"$COMMENT\"\ experience=\"$EXPERIENCE\"\ gateway=\"$GATEWAY\"\ geometry=\"$GEOMETRY\"\ ip=\"$IP\"\ submenu=\"$SUBMENU\" title=\"$TITLE\"\ \/\>"
eval "sed -e s/^<rdp_server/$ADDLINE/ $INFILE > $TMPFILE"
}
both $INFILE and $TMPFILE are declared the error I get is
./addsub: line 24: rdp_server/<rdp_server: No such file or directory
thanks
#3
Posted 08 April 2009 - 11:30 PM
here is what I get./addsub: line 27: rdp_server/$ADDLINE/: ambiguous redirect
knoppix@Microknoppix:~$ vi addsub
knoppix@Microknoppix:~$ ./addsub
./addsub: line 27: rdp_server/$ADDLINE/: ambiguous redirect
knoppix@Microknoppix:~$ vi addsub
knoppix@Microknoppix:~$ ./addsub
./addsub: line 27: rdp_server/\<rdp_server client_audio="On"\ color_depth="16"\ comment="Created by addsub script"\ experience="0"\ gateway="12.0.0.1"\ geometry="90%"\ ip=""\ submenu="" title=""\ \/\>/: No such file or directory
knoppix@Microknoppix:~$
here is the entire script
#Script Variables, hard coded values are site default
AUDIO="On"
COLOR="16"
COMMENT="Created by addsub script"
EXPERIENCE="0"
GATEWAY="12.0.0.1"
GEOMETRY="90%"
IP=""
SUBMENU=""
TITLE=""
INFILE="./testfile"
TMPFILE="./tempfile"
function writeline()
{
ADDLINE="\<rdp_server client_audio=\"$AUDIO\"\ color_depth=\"$COLOR\"\ comment=\"$COMMENT\"\ experience=\"$EXPERIENCE\"\ gateway=\"$GATEWAY\"\ geometry=\"$GEOMETRY\"\ ip=\"$IP\"\ submenu=\"$SUBMENU\" title=\"$TITLE\"\ \/\>"
sed -e s/^<rdp_server/"$ADDLINE"/ $INFILE > $TMPFILE
}
writeline
#4
Posted 08 April 2009 - 11:35 PM
ADDLINE='<rdp_server client_audio=\"$AUDIO\" color_depth=\"$COLOR\" comment=\"$COMMENT\" experience=\"$EXPERIENCE\" gateway=\"$GATEWAY\" geometry=\"$GEOMETRY\" ip=\"$IP\" submenu=\"$SUBMENU\" title=\"$TITLE\" />'
sed -e s/^<rdp_server/"$ADDLINE"/ $INFILE > $TMPFILE
gives me
knoppix@Microknoppix:~$ ./addsub
./addsub: line 27: rdp_server/<rdp_server client_audio=\"$AUDIO\" color_depth=\"$COLOR\" comment=\"$COMMENT\" experience=\"$EXPERIENCE\" gateway=\"$GATEWAY\" geometry=\"$GEOMETRY\" ip=\"$IP\" submenu=\"$SUBMENU\" title=\"$TITLE\" />/: No such file or directory
#5
Posted 08 April 2009 - 11:42 PM
thanks
I have been beeting my head on doing this in bash and python (my only choices besides pearl which I no nothing about)
#6
Posted 08 April 2009 - 11:44 PM
ed $INFILE <<EOL /^<rdp_server/c <rdp_server client_audio="$AUDIO" color_depth="$COLOR" comment="$COMMENT" experience="$EXPERIENCE" gateway="$GATEWAY" geometry="$GEOMETRY" ip="$IP" submenu="$SUBMENU" title="$TITLE"/> . wq $OUTFILE EOL
#7
Posted 09 April 2009 - 12:08 AM
but if i quote the variable is not passed its taken as a literal value
I am writing this script to let a windows admin add line (questions will fill in the data later) so I am putting it in a script, if it was me I would just open the xml file and yyp the lines and edit them, but its not for me..
I don't have ed but thanks
#8
Posted 09 April 2009 - 12:14 AM
#9
Posted 09 April 2009 - 12:44 AM
<code>
#Script Variables, hard coded values are site default
AUDIO="On"
COLOR="16"
COMMENT="Created by addsub script"
EXPERIENCE="0"
GATEWAY="12.0.0.1"
GEOMETRY="1660x1024"
IP=""
SUBMENU=""
TITLE=""
INFILE="./testfile"
TMPFILE="./tempfile"
function writeline()
{
ADDLINE="\<rdp_server\ client_audio=\"$AUDIO\"\ color_depth=\"$COLOR\"\ comment=\"$COMMENT\"\ experience=\"$EXPERIENCE\"\ gateway=\"$GATEWAY\"\ geometry=\"$GEOMETRY\"\ ip=\"$IP\"\ submenu=\"$SUBMENU\"\ title=\"$TITLE\"\ \/\>"
sed -e "s/^<rdp_server/$ADDLINE/1" $INFILE > $TMPFILE
}
writeline
</code>
but I only want to append the line after the first find ?
thanks
#10
Posted 09 April 2009 - 12:49 AM
#11
Posted 09 April 2009 - 12:53 AM
#12
Posted 09 April 2009 - 01:13 AM
{
ADDLINE="\<rdp_server\ client_audio=\"$AUDIO\"\ color_depth=\"$COLOR\"\ comment=\"$COMMENT\"\ experience=\"$EXPERIENCE\"\ gateway=\"$GATEWAY\"\ geometry=\"$GEOMETRY\"\ ip=\"$IP\"\ submenu=\"$SUBMENU\"\ title=\"$TITLE\"\ \/\>"
#sed -e "s/^<rdp_server/$ADDLINE/1" $INFILE > $TMPFILE
sed "0,/^<rdp_server/a$ADDLINE/" $INFILE > $TMPFILE
}
Thanks..
#13
Posted 09 April 2009 - 01:41 AM
just standard output
ADDLINE="\<rdp_server\ client_audio=\"$AUDIO\"\ color_depth=\"$COLOR\"\ comment=\"$COMMENT\"\ experience=\"$EXPERIENCE\"\ gateway=\"$GATEWAY\"\ geometry=\"$GEOMETRY\"\ ip=\"$IP\"\ submenu=\"$SUBMENU\"\ title=\"$TITLE\"\ \/>" #sed -e "s/^<rdp_server/$ADDLINE/1" $INFILE > $TMPFILE sed -e "/^<rdp_server/a$ADDLINE/" $INFILE -e "/^<rdp_server/q" < $INFILE
#14
Posted 26 June 2009 - 10:42 AM
In the same file I need to add at the end of each line to use it in latex, in this case I must put the sed command in single

Sign In »
Register Now!
Help

Back to top
MultiQuote