The UNIX and Linux Forums  

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
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 09:34 AM
Script Required Satadru Shell Programming and Scripting 1 05-08-2008 01:38 PM
Script required ntgobinath Shell Programming and Scripting 1 05-08-2008 12:35 PM
script required skyineyes Shell Programming and Scripting 13 06-27-2007 02:49 AM
Script help required! kev112 Shell Programming and Scripting 8 05-24-2005 05:33 AM

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

Join Date: Jun 2007
Posts: 32
sed script required

Collegues
I have a flat file with data in following structure.
(S1 (S (NP (NP (DT The) (JJ beautiful) (NN view)) (PP (IN of) (NP (JJ outside) (NNP greenery)))) (VP (VBZ adds) (NP (DT a) (NN tranquil) (NN touch)) (PP (TO to) (NP (DT this) (NN place)))) (. .)))

I have to extract the contents in ( NP ((( )))) and (VP ((( ))) and (PP ((( )),
That i have indiacted in bold.
First I have to extract the (NP (())
then
(VP ((( ))
then (PP (((()))
Any solution
With adavanced thanks and regards

Jaganadh.G
Linguist
  #2 (permalink)  
Old 07-06-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,411
Here's one way...
Code:
$ cat file1
(S1 (S (NP (NP (DT The) (JJ beautiful) (NN view)) (PP (IN of) (NP (JJ outside) (NNP greenery)))) (VP (VBZ adds) (NP (DT a) (NN tranquil) (NN touch)) (PP (TO to) (NP (DT this) (NN place)))) (. .)))

$ cat prog.awk
    {
        for (i = 2; i <= length($0); i++) {
            x = substr($0, i, 1)
            if (c > 0) {
                b = b x
                if (x == "(") c++
                if (x == ")") c--
            }
            if (c == 0 && substr($0, i, 3) ~ /^\([NVP]P$/) {
                if (b) print b
                b = x
                c++
            }
        }
    }

    END {
        if (b) print b
    }

$ awk -f prog.awk file1
(NP (NP (DT The) (JJ beautiful) (NN view)) (PP (IN of) (NP (JJ outside) (NNP greenery))))
(VP (VBZ adds) (NP (DT a) (NN tranquil) (NN touch)) (PP (TO to) (NP (DT this) (NN place))))

  #3 (permalink)  
Old 07-06-2007
jaganadh jaganadh is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 32
Thumbs up

Collegue
Thaks for the solution. It is working fine and smooth.
Jaganadh.G
Linguist
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 06:23 AM.


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