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
How to apply aix 5.3 TL8 properly on ML5 aix system ? astjen AIX 6 10-13-2008 01:02 PM
Need to apply Checks SSh/SCP niceboykunal123 Shell Programming and Scripting 0 04-16-2008 01:41 AM
How to apply the awk commnad ? preethgideon UNIX for Dummies Questions & Answers 3 10-30-2006 09:32 PM
How to apply patches in HP-UX ? bbose HP-UX 2 12-30-2005 09:34 PM
Apply to end of line sysera Shell Programming and Scripting 4 07-12-2005 11:23 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 01-23-2009
vanitham vanitham is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 56
How to apply brackets?

Hi,

I have a query term like this:

$query="apple NOT banana AND fruits";

$query="a1 NOT prim1 AND a2 NOT a3 OR a5";

I want to apply brackets to the NOT terms and the output should be like this:

Code:
$query="apple NOT (banana) AND fruits";
$query="a1 NOT (prim1) AND a2 NOT (a3) OR a5";
How can i do this??

Regards
Vanitha

Last edited by vanitham; 01-23-2009 at 07:01 AM..
  #2 (permalink)  
Old 01-23-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try this:

Code:
awk '{for(i=1;i<=NF;i++){if($i=="NOT"){i++;$i="("$i")"}}}1'
Regards
  #3 (permalink)  
Old 01-27-2009
vanitham vanitham is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 56
Quote:
Originally Posted by Franklin52 View Post
Try this:

Code:
awk '{for(i=1;i<=NF;i++){if($i=="NOT"){i++;$i="("$i")"}}}1'
Regards
Hi,

How can i do that in perl???

Regards
Vanitha
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 05:57 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