This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / Coding is a pain ... especially coding shell script ... HELP on sed and variable issue on kshellfile content: (this file is named a.sql, one line)
sqlplus $CONNECT
script: (note: there is a "/" in the V_A var)
V_A=a/a@a
cat a.sql |sed -e 's/\$CONNECT/$V_A/g' <--- BUG ME SO FREAKY!!!
The expected output is:
sqlplus a/a@a
How to write correct second line in script?
Thanks!
-ra_95(小人-过度了...过度了);
2005-1-27
{299}
(#2097306@0)
-
V_A='a\/a\@a';
cat a.sql |sed -e 's/$CONNECT/'$V_A'/g'
-yuheng(虞衡);
2005-1-27
(#2097344@0)
-
wokao ... yuan2lai2ru2ci3ah1!! great, duo1xie4!~! 呵呵,我的意思是这CODE就比我的拼音还难哪!多谢!
-ra_95(小人-过度了...过度了);
2005-1-27
(#2097364@0)
-
give up :((: sed: Function s/\//\\/g cannot be parsed. ....
-ra_95(小人-过度了...过度了);
2005-1-27
(#2097393@0)
-
I tried in my computer, no problem. I used sh, ksh should be working too. which sh are you using?
-yuheng(虞衡);
2005-1-27
(#2097430@0)
-
AIX shell ... I just cannot replace anything to "\" (backslash) ...sigh ...
-ra_95(小人-过度了...过度了);
2005-1-27
(#2097469@0)
-
AIX should be using ksh. Anyway sh should be working bah.
-yuheng(虞衡);
2005-1-27
(#2097537@0)
-
Regular Expression apply to all shell. all shell ksh, bsh, csh and sh support RE. If need more, the Extended RE can be used. See difference between the two on man page of grep and egrep.
-647i(盲人协会);
2005-1-27
(#2097734@0)
-
by Regular Expression: '\' is represent by '\\'. if the expression parses two times, \\\\ need to be used to get a \
-647i(盲人协会);
2005-1-27
(#2097729@0)
-
to change '/' --> '\', use 's/\//\\\/g' works; BUT, to change '/' -->'\/', 's/\//\\\\//g' does not work ... hehe ... '\\\' can be '\' but '\\\\/' is not '\/' kao
-ra_95(小人-过度了...过度了);
2005-1-28
(#2098150@0)
-
I don't have an AIX to try. on my HP workstation, it's working fine. Did you copy and past my whole command line into your script? I did change value of V_A too.Why can't you put #!/usr/bin/ksh infront of your script file? Or rather, run the script by $ksh ./c
-yuheng(虞衡);
2005-1-28
{100}
(#2098192@0)
-
there is a command 'chsh' to change shell. it change content in /etc/passwd file.
-647i(盲人协会);
2005-1-28
(#2098507@0)
-
#2097368
-647i(盲人协会);
2005-1-27
(#2097735@0)
-
lllthe file is
a/b@c
va=a\\\/b\\@c
vb=x\\\/y\\@z
sed -e "s/$va/$vb/g" < file
Note the difference between " and '
" can do replace ment of variable, ' doesn't
-647i(盲人协会);
2005-1-27
{187}
(#2097368@0)