REGEX help required and some sed/awk help as well


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting REGEX help required and some sed/awk help as well
# 1  
Old 07-15-2017
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..
# 2  
Old 07-15-2017
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.
# 3  
Old 07-15-2017
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Sed/awk : to grep only required pattern disk

Hi Experts, Need help with the following: Desired output: Only want to get the output marked in green. The file: --- Physical volumes --- PV Name /dev/disk/disk4704 PV Status available Total PE 6399 Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

To print lines between 2 timestamps using awk|sed and regex

Hi, I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better) with some regex pattern. dt_1=`date +%h" "%d", "%Y\ %l -d "1 hour... (10 Replies)
Discussion started by: sarah-alikhan31
10 Replies

4. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

5. Shell Programming and Scripting

Question on awk/sed/regex

I plan to do something like this in awk that's embedded in a shell script. I have extracted a text file using awk and the output is before example: <USDOLLARS|xxx> I want to use get rid of the starting "<" and anything after the pipe "|" after example: USDOLLARS How do I do that?? I... (8 Replies)
Discussion started by: deadyetagain
8 Replies

6. Shell Programming and Scripting

Selecting a part of the text (regex pattern, awk, sed)

Hello, let's start by giving you guys a few examples of the text: "READ /TEXT123/ABC123" "READ /TEXT123/ABC123/" "READ TEXT123/ABC123" "READ TEXT123/ABC123/" "READ TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123/" TEXT and ABC can be and I... (5 Replies)
Discussion started by: TehOne
5 Replies

7. Shell Programming and Scripting

sed to awk (regex pattern) how?

Hello, I am trying to covert a for statement into a single awk script and I've got everything but one part. I also need to execute an external script when "not found", how can I do that ? for TXT in `find debugme -name "*.txt"` ;do FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'` how... (7 Replies)
Discussion started by: TehOne
7 Replies

8. Shell Programming and Scripting

Help required with awk/sed

Hi I have a file, with format like: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,42,25 G|H|I|55,66 L|E|Q|25,31,94 output required: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,25 L|E|Q|25,31 Input File Format: All columns are seperated using |, last column... (8 Replies)
Discussion started by: New to awk
8 Replies

9. Shell Programming and Scripting

Help required in sed or awk.

Hi All, I need to pick up data on both sides of "=" sign. For eg, following is the context that I have. 125.156.125.147=machine1 147.125.185.156=machine2 147.125.185.159=machine3 Can I have the ip address in one variable and machine name in another variable using sed or awk. ... (1 Reply)
Discussion started by: nua7
1 Replies

10. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies
Login or Register to Ask a Question