[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Shell script help please

Posted on 2015-02-10
2
Medium Priority
?
103 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

650 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