Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

REGEX help required and some sed/awk help as well

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-15-2017   -   Original Discussion by mojoman
mojoman mojoman is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 12 October 2017, 2:21 PM EDT
Posts: 255
Thanks: 0
Thanked 1 Time in 1 Post
REGEX help required and some sed/awk help as well

Hi guys,

I am coding a bash script that makes use of php scripts to pull URL's from a website. These url links will have numbers in them like 0.2.3
I want to make a regex that will yield me such numbers if I use a command like preg_grep.

Question1: I need a regex that will tell my preg_grep to get any three digit number separated by two dots. Would d\.d\.d be an appropriate regex?

Question2: As well once I get the number I need to strip it of its dots. In bash would this tactic work for numbers:

Code:
$ foo=1.2.3
$ echo "${foo//./}"
testtesttest

Or should I use sed?


But in php could I use the following
PHP Code:
$var1 "10.000";
$var1 str_replace("."""$var1); 


Question#3 If I use the php code could the result $var1 be used in a comparison to see which number stored in $var2 is greater using a if comparison condition?

Last edited by mojoman; 07-15-2017 at 11:07 AM..
Sponsored Links
    #2  
Old Unix and Linux 07-15-2017   -   Original Discussion by mojoman
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 18 November 2017, 3:16 PM EST
Location: NM
Posts: 11,239
Thanks: 570
Thanked 1,116 Times in 1,030 Posts
Q1. is the string embedded in text or standalone, i.e., how does it appear in the input? php preg_whatever() uses PCRE.

Q2. use bash. Invoking an external command adds overhead.
The same concept applies in php, use the library module: str_replace().

Q3. Do not use number comparisons until you have stripped the dots out of the text.
1.2.3 is NOT a number and will throw an error. You can use string comparison on "1.2.3" if you want.
Sponsored Links
    #3  
Old Unix and Linux 07-15-2017   -   Original Discussion by mojoman
mojoman mojoman is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 12 October 2017, 2:21 PM EDT
Posts: 255
Thanks: 0
Thanked 1 Time in 1 Post
Q1. Numbers would be in URL's like Release SCAP Security Guide 0.1.23 Release Notes * OpenSCAP/scap-security-guide * GitHub

Q1. Seems like I can do it in bash or php. But since main part of program is in shell I will do it there.

Q3. In shell/php can I do a conditional check on "1.2.3" and "1.2.4" o see which is greater in an if statement?

---------- Post updated at 12:28 PM ---------- Previous update was at 11:51 AM ----------

In my last reply to you, I just posted the URL but the forum seems to have resolved it. Should have seen that parse link option. I would be performing the REGEX on https://github.com/OpenSCAP/scap-security-guide/releases/tag/v0.1.23
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH RobbieTheK Shell Programming and Scripting 0 03-20-2017 04:00 PM
Perl, RegEx - Help me to understand the regex! alex_5161 Shell Programming and Scripting 2 06-12-2015 02:01 PM
Converting perl regex to sed regex suntzu Shell Programming and Scripting 1 10-30-2010 07:16 AM
Regular expression (regex) required shams11 Shell Programming and Scripting 10 01-07-2010 01:27 AM
Getting required fields from a test file in required fromat in unix rdhanek Shell Programming and Scripting 7 07-22-2009 12:35 PM



All times are GMT -4. The time now is 06:36 AM.