Solved

Shell script help please

Posted on 2015-02-10
2
99 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
2 Comments
 
LVL 84

Assisted Solution

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

Accepted Solution

by:
woolmilkporc earned 400 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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 …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

820 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