Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex – Checking if [x]/[y] y is greater than x

I’m trying to capture [x]/[y] and if y is greater than x using a regex pattern.
The input is in the second column ($2)

Example input:

NAME1 0/1
NAME2 0/2
NAME3 1/2
NAME4 1/3
NAME5 2/2
NAME6 1/1

Output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NAME1 0/1
NAME2 0/2
NAME3 1/2
NAME4 1/3

What would be the right approach using awk?

I’ve done so far:

cat pods | grep -v Completed | awk -e '$2 ~ "[0-9]/[0-9]"'

I’m not sure how to proceed or to check if the second [0-9] is greater.

>Solution :

With your shown samples, please try following awk code. Simple explanation would be, in main program splitting 2nd field using awk‘s split function and splitting 2nd field into array named arr using field separator /, then checking condition if 2nd element of array is GREATER than 1st element then printing that line.

awk  '{split($2,arr,"/")} arr[2]>arr[1]' Input_file

OR As an alternate solution one could also use:

awk -F' |/' '$3>$2' Input_file
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading