problem String
icecream= \{ smart peopleLink "good" LC "happy" ,
smartpeopleLink "dull" LC "sad" \}
aend = \{smart vc4 eatr kalu\}
output needed
smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu
I am new to use shell script,
facing problem to fetch above result specially when curly braces are
in different lines.
i am using ksh
Any one with some idea to help.............
thanks
kris
FILE:
~~~~~~~~~~~~~~~~~~
icecream= { smart peopleLink "good" LC "happy" ,
smartpeopleLink "dull" LC "sad" }
aend = {smart vc4 eatr kalu}
awk code:
awk ' BEGIN { p=0 }
{
for(i=1; i<length($0); i++)
{
test=substr($0, i, 1)
if(test=="{") {
p=1
continue
}
if(test=="}") {
p=0;
}
if(p==1) {
printf("%s", test)
}
}
printf("\n") } ' filename
output
smart peopleLink "good" LC "happy" ,
smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu
jim thanks
but i need to have output as
output needed
smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu
is there any way to fetch all the contents that come in between curly braces, "\{" and "\},"
regards
kris
reborg
August 9, 2007, 5:54pm
4
sed -n -e '$!N' -e 's/\n//g' -e 's/.*{\([^{][^{]*\)}.*/\1/gp' filename
If you have Python and open to alternatives:
#!/usr/bin/python
import re
data=open("file").read()
result=re.compile("{(.*?)}",re.M|re.DOTALL).findall(data)
for item in result:
item=item.replace("\n","")
print item
output:
# python test.py
smart peopleLink "good" LC "happy" ,smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu