For getting value between the braces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For getting value between the braces
# 1  
Old 10-14-2014
For getting value between the braces

Hi

I have a file called tmp with the content as below
Code:
more tmp
   NAMELIST(Hari)
   NAMELIST(Raju)

I want to get the values between the brackets.

When I executed the below command on zlinux I get the output which I wanted
Code:
more tmp |awk -F'[()]' '{print $2}'

But when I execute the same in the Solaris server its throwing me a blank output.

Any suggestion on what what wrong am I doing or can this be done in a different way.

Thanks
Hari M






Hari
Raju

Last edited by rbatte1; 10-15-2014 at 08:17 AM.. Reason: Added CODE tags for files
# 2  
Old 10-14-2014
More importantly on Solaris/SunOS system, change awk at the start of your script to /usr/xpg4/bin/awk or /usr/xpg6/bin/awk or nawk

--

Last edited by Akshay Hegde; 10-14-2014 at 05:36 PM..
# 3  
Old 10-14-2014
Thanks for the quick reply, nawk has worked in solaris but not in zlinux.

Is there any one format i can use which will work in both zlinux and solaris.
# 4  
Old 10-14-2014
Gnu grep
Code:
$ echo 'NAMELIST(Hari)' | grep -oP '\(\K[^)]+'
Hari


Sed

Code:
$ echo 'NAMELIST(Hari)' | sed 's/.*(\(.*\))/\1/'
Hari

Perl
Code:
$ echo 'NAMELIST(Hari)' | perl -pe 's/.*\((.*)\)/$1/'
Hari

Code:
$ echo 'NAMELIST(Hari)' | perl -lanF"[()]" -e 'print $F[1]'
Hari

Code:
$ echo 'NAMELIST(Hari)' | perl -pe 's/.*\((.+?)\).*/$1/;'
Hari


Shell

Code:
$ while IFS="()" read a b; do echo "$b"; done <<<'NAMELIST(Hari)'
Hari

For file use like this
Code:
$ while IFS="()" read a b; do echo "$b"; done <infile

Awk

Code:
$ echo 'NAMELIST(Hari)' | awk 'NR > 1 {print $1}' RS='(' FS=')'
Hari

Code:
$ echo 'NAMELIST(Hari)' | awk  'gsub(/.*\(|\).*/,"")'
Hari

Code:
$ echo 'NAMELIST(Hari)' | awk  '{split($0,A,/[()]/);  print A[2]}'
Hari


Last edited by Akshay Hegde; 10-14-2014 at 05:39 PM..
This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

When curly braces needed?

Hello, i was trying to find get a command to list duplicated files so i tried ls dir1 dir2 | awk '{x++}' and it didnt work. After a bit of searching online i found that it works without the curly braces ls dir1 dir2 | awk 'x++' I thought the curly braces were needed in awk so... (6 Replies)
Discussion started by: andy391791
6 Replies

2. Shell Programming and Scripting

Curly braces in sed

Hi, I have below command in one of the script. Can you please let me know what does the curly braces do over here \{1,\}. The remaining part of the code atleast I am able to understand. sed -n 's/.*\-\()\{1,\}\)\-.*/\1/p' (13 Replies)
Discussion started by: tostay2003
13 Replies

3. UNIX for Dummies Questions & Answers

How do I pull the value between curly braces?

Hi everyone, I've got a file that looks like this: uid{508}pid{22224}pname{/PPROGRAM/pprgramx -profile:LIVE -serv:as ... I want to pull the value of pid between the curly braces, or 22224 in this example. pid is always the second pair of curly braces, but the length of the number is... (7 Replies)
Discussion started by: Scottie1954
7 Replies

4. Shell Programming and Scripting

TCL - Question regarding Braces {}

Hello everyone, What is the difference between these two tcl commands: (A) --> puts "ERROR!!! ${current_name}/${opt} is not found." (B) --> puts "ERROR!!! $current_name/$opt is not found." Are the braces needed to be put? Or both A and B has the same output? (5 Replies)
Discussion started by: mar85
5 Replies

5. Shell Programming and Scripting

tar --exclude with curly braces

I'm having trouble understanding the exclude option in tar. From some web sites, it seems one is able to exclude several strings by enclosing them in curly brackets. However it seems to be "random" what gets excluded when using the curlies. I've been using the exclude-from=myfile option in a... (12 Replies)
Discussion started by: majest
12 Replies

6. Shell Programming and Scripting

sed to remove braces from a file

i need to search for user belonging to group 'macusr' and the extract the user name . i am able to write a oneliner for this using awk + sed + tr i am using tr to chop off '()' from the output. but i want to use it in sed itself . can someone please help me with that file contents ... (7 Replies)
Discussion started by: chidori
7 Replies

7. Shell Programming and Scripting

grep matter between braces

#include<header.h> void classname :: pvvd_init ( abcd ,efgh ,ijkl ,mnop ) { rvcl_tabl_name_tabl.pvvd_init ( xxxx ,"tabl_mame" ) ; ... (2 Replies)
Discussion started by: ultimatix
2 Replies

8. Shell Programming and Scripting

Finding opening and closing braces

I am reading a cpp file thru shell script . There are many fuctions inside the cpp file eg pvvd_fncn_name1 { ..... something } pvvd_fncn_name2 { ..... something } what I require is a method to find the first opening brace and the coresponding last brace and search... (2 Replies)
Discussion started by: ultimatix
2 Replies

9. Shell Programming and Scripting

Use of curly braces with variables

Hi, I am new to shell scripting.I have worked somewhat with Perl though. I am not able to find what the second line does and how does it do. <code> FP_RUNNING=`service filepool status` FP_RUNNING=${FP_RUNNING%% *} <\code> After the first line,the variable FP_RUNNING stores '1 FilePool... (2 Replies)
Discussion started by: abhinavsinha
2 Replies

10. Shell Programming and Scripting

what is the significance of braces and spaces???

Hi , i have few doubts about the braces and spaces which are quite often used: for instance: when i try the belo command it will not work export variable= cat filename rather when i try the cat command without any space it works fine export variable=cat filename and... (3 Replies)
Discussion started by: ahmedwaseem2000
3 Replies
Login or Register to Ask a Question