![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "find command" to find the files in the current directories but not in the "subdir" | swamymns | Shell Programming and Scripting | 9 | 07-22-2008 11:23 AM |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| grep/cat/more -- search in a txt file and display content from a specific "keyword" | I-1 | UNIX for Dummies Questions & Answers | 4 | 02-21-2007 04:57 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
grep to find content in between curly braces, "{" and "},"
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:
Code:
~~~~~~~~~~~~~~~~~~
icecream= { smart peopleLink "good" LC "happy" ,
smartpeopleLink "dull" LC "sad" }
aend = {smart vc4 eatr kalu}
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
Code:
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 |
|
||||
|
If you have Python and open to alternatives:
Code:
#!/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
Code:
# python test.py smart peopleLink "good" LC "happy" ,smartpeopleLink "dull" LC "sad" smart vc4 eatr kalu |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|