Solved

Shell script help please

Posted on 2015-02-10
2
100 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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix process listing into CSV format 3 87
NTPD Client Port Usage 12 94
how to write and save a unix script 12 36
change script to get csv file on the prompt 8 32
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

734 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