How to apply brackets?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to apply brackets?
# 1  
Old 01-23-2009
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  
Old 01-23-2009
Try this:

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

Regards
# 3  
Old 01-27-2009
Quote:
Originally Posted by Franklin52
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply acl?

hi, i am facing problem with acls, as a root i logged in and applied acl for directory(dir5),by using command setfacl -m u:user1:rwx dir5 but when i logged in as user1 i am not able to access that folder even though i applied full permission to that directory as a root.can any one help me on... (2 Replies)
Discussion started by: cmanoj489
2 Replies

2. Shell Programming and Scripting

Brackets

Hi all. i need a small help. i have written an exit code, which will check whether mo.sh is successful or not. if the status is >0 it will exit the shell. 1>Do you guys think it is a correct way to write? 2>what if i change the double bracket to single. how will it change the o/p. ... (1 Reply)
Discussion started by: sub
1 Replies

3. Shell Programming and Scripting

Apply file permission

Hi All, I would like to read the permission from a file and wanted to apply the same permission to another file. say for example, f1 755 first...i have to read the permission type (which is differ for each file) and need to apply the same for f2 a1 666 i have to get this... (5 Replies)
Discussion started by: karthi_mrkg
5 Replies

4. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Shell Programming and Scripting

How to get the value in the first brackets

Hello, I am trying to write a script using ksh. And I want to get the value within the first brackets of a string. For example: 14/04/11 11:35: 00 This is (nn) from the earth. Then i hope to get nn in this case. Can any one advise me how to implement it? Thank you very much! nn (2 Replies)
Discussion started by: n_n
2 Replies

6. Shell Programming and Scripting

Get value between brackets

Hi I am having hard time getting this right and need some help. I Have several log files, and everyone contains the following 3 lines at the end: 4 ETW000 Disconnected from database. 4 ETW000 End of Transport (0000). 4 ETW000 date&time: 13.01.2011 - 08:03:28 I need to capture the value... (7 Replies)
Discussion started by: nimo
7 Replies

7. Shell Programming and Scripting

Re-apply the file permission

Hi, I having an issue with file permission. To fix it I need to read the file's existing permission and re-apply the same permission to the file. This has to be done for every single file under a mount point. I'm novice in scripting. Help me with this in shell scripting. # ls -l /dev/null... (10 Replies)
Discussion started by: agent001
10 Replies

8. UNIX for Dummies Questions & Answers

How to apply static ip address

Hi there, I have a Debian 5.0 server newly installed. By default, the ip address is given by dhcp. pegase:~# grep '^' /etc/network/interfaces auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp pegase:~# head -2 /etc/hosts 127.0.0.1 localhost 127.0.1.1 ... (1 Reply)
Discussion started by: chebarbudo
1 Replies

9. UNIX for Dummies Questions & Answers

ldapmodify: keystroke to apply changes

Hi, I need to modify some entries in LDAP, but with what keystroke do I exit and apply the changes? Thanks Brissix (0 Replies)
Discussion started by: brissix
0 Replies

10. HP-UX

How to apply patches in HP-UX ?

Hi: One basic qs. how to apply patches in hp-ux ? Thanks in advance. (2 Replies)
Discussion started by: bbose
2 Replies
Login or Register to Ask a Question