View Full Version : how to add a space as prefix through bash script ?
change.chases.me
December 30th, 2008, 02:17 PM
i am trying to achieve the following transformation through sed command :
hello --> <a href="xxx">hello</a>
but the space between 'a' and 'href' is creating problems, as the arguments of sed command are themselves separated by spaces.
thanks.
jpkotta
December 30th, 2008, 02:29 PM
Quoting.
echo hello | sed "s#\(.*\)#<a aref=\"xxx\">\1</a>#"
snova
December 30th, 2008, 02:34 PM
Either quote the regexp, or escape the space by putting a backslash before it.
change.chases.me
December 31st, 2008, 09:33 AM
thanks for the solutions, but i still cant get my stuff working.
the actual problem is that, i am calling a shell script from java program. here is the code of the script i am running through the program:
sed -i "s/$2/$3$2$4/g" $1
and this is a part of the java code, the string s is being executed through the program :
String s = "sh usesed ./* hello <a href=\"hello.html\"> <\\/a>";
the purpose of the system is to scan all the files in the current folder, look for a dynamic word (in above cases i have taken "hello") and make it an html link to dynamic_word.html ("hello.html" in above case).
PS : This is not a homework problem (as some of the people may think).
ghostdog74
December 31st, 2008, 10:35 AM
you should look into Java's own substitution functions or regular expression libraries.
change.chases.me
December 31st, 2008, 10:47 AM
you should look into Java's own substitution functions or regular expression libraries.
I have done it that way, it is just that I want to try this way too.... something new.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.