[SOLVED] perl: regex exact match using if statement
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I tried few different ways to return a unique result but it's not working.
I have a script that goes through the below sample data set and then return matches based on third column. So it extracts column three and then goes through the data again to dissect each line. Notice there are dupes for each app(ie: sweep running on zpd58 and tdp58).
So when I run this part of the code, I think it's greedy and matches both SPREADSOOT and SPREADSOOT2 when it tries to match for SPREADSOOT. And notice I want to only process lines starting with "z". I tried all different variation and no luck:
if(($data =~ m/^zpd/) and ($routes =~ m/$routes\b0$data/)){
if(($data =~ m/^zpd/) and ($routes =~ m/$routes\|$data/)){
if(($data =~ m/^zpd/) and ($routes =~ m/$routes?.*$data/)){
OUTPUT:
....
The route is SWEPCRS app is sweep host: zpd58 and vm: vm2 quote:299.352.773.112
The route is SPAAN2 app is spt2 host: zpd71 and vm: vm16 quote: 299.352.773.112
The route is SPREADSOOT app is mkt host: zpd71 and vm: vm14 quote: 299.352.773.113
The route is SPREADSOOT app is mkt host: zpd71 and vm: vm14 quote: 299.352.773.113
The route is SPREADSOOT2 app is mkt host: zpd71 and vm: vm15 quote: 299.352.773.111
So when it's processing SPREADSOOT, how do I get it to not process or match against data for SPREADSOOT2?
Simplify the problem: begin with split. Since this is “pipe-delimited data,” first split it by pipe, thus creating an array, then concentrate on the one column of interest. This should completely eliminate concerns of “greediness.”
Last edited by sundialsvcs; 12-29-2021 at 06:17 PM.
#!/bin/sh
file='input_data'
while IFS='.|' read -r h vm _ a r q
do
case $h in z*)
echo "The route is $r app is $a host: $h and vm: $vm quote: $q"
esac
done <"$file"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.