Solved

Shell script help please

Posted on 2015-02-10
2
94 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
Comment Utility
egrep -nv ${VALID//,/|} File.txt
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 400 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now