The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-09-2007
keshav_rk keshav_rk is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
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
  #2 (permalink)  
Old 08-09-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
FILE:
Code:
~~~~~~~~~~~~~~~~~~ 
icecream= { smart peopleLink "good" LC "happy" , 
smartpeopleLink "dull" LC "sad" } 
aend = {smart vc4 eatr kalu}
awk code:
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
Code:
 smart peopleLink "good" LC "happy" ,
smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu
  #3 (permalink)  
Old 08-09-2007
keshav_rk keshav_rk is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
Question

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
  #4 (permalink)  
Old 08-09-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Code:
sed -n -e '$!N' -e 's/\n//g' -e 's/.*{\([^{][^{]*\)}.*/\1/gp' filename
  #5 (permalink)  
Old 08-09-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
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
output:
Code:
# python test.py
 smart peopleLink "good" LC "happy" ,smartpeopleLink "dull" LC "sad"
smart vc4 eatr kalu
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0