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
Regex extraction abdurrouf Shell Programming and Scripting 11 06-24-2008 12:48 PM
Regex deepakpv Shell Programming and Scripting 6 03-28-2007 04:18 AM
Regex?? Please help lunac UNIX for Dummies Questions & Answers 7 01-30-2007 01:13 PM
use of regex on grep solea UNIX for Dummies Questions & Answers 0 09-30-2004 11:13 AM
sed regex Shakey21 UNIX for Dummies Questions & Answers 4 01-31-2002 09:16 PM

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 06-30-2008
pppswing pppswing is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 14
Smile Regex

Hello
I need to make a regex.

I have a file myfile, in this file I want to find a number situated after PAYSLOT=
Before PAYSLOT is the begining of line (I guess
Code:
^
) and
after the number is the end of line (I guess
Code:
$
) .
I want to echo this number (I guess
Code:
$1
) and put it in my variable payslot.

Code:
payslot=`cat $myfile | grep PAYSLOT | awk \^PAYSLOT=($1)$\ `
  #2 (permalink)  
Old 06-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
if that is the case, regexp is not needed. KISS
Code:
awk -F"=" '{print $NF}'  myfile
  #3 (permalink)  
Old 06-30-2008
risby risby is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 11
Quote:
Originally Posted by ghostdog74 View Post
if that is the case, regexp is not needed. KISS
Code:
awk -F"=" '{print $NF}'  myfile
If you want to KISS it then the cat isn't required but the grep is if the file contains more lines than just the one starting with PAYSLOT:
Code:
payslot=`grep PAYSLOT $myfile | awk -F"=" '{print $NF}'`
but if you want to use the regex then sed might do:
Code:
payslot=`grep PAYSLOT $myfile | sed -e 's/^PAYSLOT=\([0123456789]\+\)$/\1/'`
  #4 (permalink)  
Old 06-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by risby View Post
If you want to KISS it then the cat isn't required but the grep is if the file contains more lines than just the one starting with PAYSLOT:
Code:
payslot=`grep PAYSLOT $myfile | awk -F"=" '{print $NF}'`
i hope you are not responding to me. the above is simply
Code:
payslot=`awk -F"=" '/PAYSLOT/{print $NF}'`
Quote:
but if you want to use the regex then sed might do:
Code:
payslot=`grep PAYSLOT $myfile | sed -e 's/^PAYSLOT=\([0123456789]\+\)$/\1/'`
i am sure grep is not needed here too, unless i mistaken about the requirement
  #5 (permalink)  
Old 06-30-2008
risby risby is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 11
Quote:
Originally Posted by ghostdog74 View Post
i hope you are not responding to me. the above is simply
Code:
payslot=`awk -F"=" '/PAYSLOT/{print $NF}'`
i am sure grep is not needed here too, unless i mistaken about the requirement
I was responding to you ghostdog74. The example code you have given above will not store anything in the environment variable because no input is specified to the awk command.

Also, if you leave out the grep you are assuming that the input file does not contain anything other than the single line starting with "PAYSLOT". The OP does not say that that is the case.

Hope this helps
  #6 (permalink)  
Old 06-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by risby View Post
I was responding to you ghostdog74. The example code you have given above will not store anything in the environment variable because no input is specified to the awk command.
Code:
awk -F"=" '/^PAYSLOT/{print $NF}'  myfile
that should do it.

Quote:
Also, if you leave out the grep you are assuming that the input file does not contain anything other than the single line starting with "PAYSLOT". The OP does not say that that is the case.

Hope this helps
this:
Code:
grep PAYSLOT $myfile | awk -F"=" '{print $NF}'
is the same as this:
Code:
awk -F"=" '/PAYSLOT/{ print $NF}' $myfile
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:08 PM.


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