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
Regular Expressions HELP - PERL maxmave UNIX for Dummies Questions & Answers 1 06-04-2008 12:15 PM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 03:10 PM
Regular Expressions sandeep_hi Shell Programming and Scripting 6 06-12-2006 02:12 AM
Perl regular expressions... DrRo183 Shell Programming and Scripting 1 04-26-2006 09:28 PM
Regular expressions in sed mfreemantle UNIX for Dummies Questions & Answers 3 02-11-2002 09:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-04-2008
maxmave maxmave is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 21
Regular Expressions HELP - PERL

Hello,

Code:
$line=USING (FILE '/TEST1/FILENAME'5000)
I want to reterive the value between ' and ) which is 5000 here.

i have tried out the following expressions ...

Type 1 : $Var1=`sed -e 's/.*\' //' -e 's\).*$/' $line`;
Type 2 : $Var1=`echo $line | awk -F"\'" '{print $2}' | awk -F"\\)" '{print $1}'`;
Type 3 : $Var1=`echo $line | sed 's/.*\' //' | sed 's/\).*$//'`;
Type 4 : $Var1=`echo $line | sed 's/.*\' //' | sed 's/\)$//'`;
Type 5 : $Var1=`echo $line | sed 's/.*File //' | sed 's/Closing.*$//'`;
Type 6 : $Var1=`echo $line | sed 's/"//g' | sed 's/\)//g' | awk -F"\'" '{print $2}'`;
Type 7 : $Var1=`sed 's/.*'\(.*\)).*/\1/' $line`;

but nothing is working out, i am always getting an error saying that
Code:
sh: -c: line 0: syntax error near unexpected token `('
Any Suggestions will be helpful

Thanks

Rahul

Last edited by Yogesh Sawant; 06-05-2008 at 03:56 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-04-2008
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
Hope this helps:

echo $line | sed -e 's/[()]//g' | awk -F"'" '{print $3}'
5000
  #3 (permalink)  
Old 06-04-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 741
Code:
line="USING (FILE '/TEST1/FILENAME'5000)"

echo $line | awk -F\' '{split($3, a, /)/);print a[1]}'
5000
  #4 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Or, finally, with Perl:

Code:
if ($line =~ m/'(\d+)\)/) { $Var1=$1 }
The reason you were getting syntax errors is that backticks in Perl will undergo what the documentation calls "double-quotish" expansion. Basically, this means that if you want a backslash to be passed to the shell, you will need to double it, because Perl already parses one level of backslashes. Also, the value of $line is being interpolated by Perl, so the shell sees the literal value echo USING (FILE '/TEST1/FILENAME'5000) without any quoting, and complains about the opening parenthesis. You can get around this with proper quoting; but of course, for trivial string manipulations, Perl itself is actually much better suited than the shell.
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 10:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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