?
Solved

Shell script help please

Posted on 2015-02-10
2
Medium Priority
?
102 Views
Last Modified: 2015-02-16
Hi Experts,

I need some help on a shell script. Many thanks in advance.

I have a valid name variable ..eg. VALID=PROD,CAT,ORD,CASH
I do have a txt file with content as below.
Eg. File.txt
XXXX_PROD_YYYY
XX_RES_YYYY
XXX_CAT_YYYY

I need to check if the lines in the file are valid as per VALID assignment.
So in this case line1 and line3 are Valid and line2 is invalid.

Please advice.

Thanks
0
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 400 total points
ID: 40601079
egrep -nv ${VALID//,/|} File.txt
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 total points
ID: 40601095
while read line; do
   if grep -qE ${VALID//,/|} <<< $line ; then
     echo "LINE is valid: $line"
       else echo "LINE is invalid: $line"
   fi
done < File.txt
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question