iccaros Posted April 9, 2009 Report Share Posted April 9, 2009 I have a bash script where I am trying to get this funtion to workit needs to find the first instance of a line and append a line after itfunction 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 directorythanks Quote Link to post Share on other sites
jcl Posted April 9, 2009 Report Share Posted April 9, 2009 Drop the eval. Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 thanks for the reply but it still fails for mehere is what I get./addsub: line 27: rdp_server/$ADDLINE/: ambiguous redirectknoppix@Microknoppix:~$ vi addsub knoppix@Microknoppix:~$ ./addsub ./addsub: line 27: rdp_server/$ADDLINE/: ambiguous redirectknoppix@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 directoryknoppix@Microknoppix:~$ here is the entire script#Script Variables, hard coded values are site defaultAUDIO="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 Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 going to this 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 > $TMPFILEgives meknoppix@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 Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 really I want to find the first match then add my line, not to everyline that matchesthanksI have been beeting my head on doing this in bash and python (my only choices besides pearl which I no nothing about) Quote Link to post Share on other sites
jcl Posted April 9, 2009 Report Share Posted April 9, 2009 You have to quote the argument to sed. FWIW, I think it would be easier to use ed and a here-doc: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 $OUTFILEEOL Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 hmmmbut if i quote the variable is not passed its taken as a literal valueI 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 Quote Link to post Share on other sites
jcl Posted April 9, 2009 Report Share Posted April 9, 2009 but if i quote the variable is not passed its taken as a literal valueDouble-quote.I don't have ed but thanksWhere did you find a system with bash and sed but not ed? How about ex? Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 ok this is close <code>#Script Variables, hard coded values are site defaultAUDIO="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 Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 Where did you find a system with bash and sed but not ed? How about ex?Knoppix.. Who knows.. maybe I should use awk...I am so out of bash scripting I feel dumb.. Quote Link to post Share on other sites
jcl Posted April 9, 2009 Report Share Posted April 9, 2009 You could use a command block and b in sed but... blech. Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 got it.. {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 > $TMPFILEsed "0,/^<rdp_server/a$ADDLINE/" $INFILE > $TMPFILE} Thanks.. Quote Link to post Share on other sites
iccaros Posted April 9, 2009 Author Report Share Posted April 9, 2009 ok change but I can noit get it to write to the file just standard outputADDLINE="\<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 > $TMPFILEsed -e "/^<rdp_server/a$ADDLINE/" $INFILE -e "/^<rdp_server/q" < $INFILE Quote Link to post Share on other sites
ibionika Posted June 26, 2009 Report Share Posted June 26, 2009 even more confused now.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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.