Validating a formatted message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validating a formatted message
# 1  
Old 08-07-2003
Question Validating a formatted message

I'm trying to write a shell script that will validate a format of a data file we recieve every night.

What I'm looking for is to ensure there are 8 pipes "|" before an email address and 9 pipes after the email address.

I was also looking to do this in one of two ways -
a) Grabbing random lines out of the files and then checking them. I don't have any idea on how to do this - I did a search on random number generators but my knowledge of scripting is slim.

b) Checking the whole file (which can be a max of 200k records).

Any help would be appreciated.

Thank you!!!

Brian
# 2  
Old 08-07-2003
Post some sample lines.
# 3  
Old 08-07-2003
Quote:
Originally posted by Perderabo
Post some sample lines.
Of the data file?

It's going to be something like this (at the bare minimum):

Code:
||||||||123456@abc.com|||||||||


There may be data in the columns, but only 1 email address (hence, only one @ sign).

Let me know if you need more information..

Brian
# 4  
Old 08-07-2003
This should do it. The code looks odd, I know. But it will run pretty quickly.
Code:
#! /usr/bin/ksh
integer errors
errors=0
IFS=""
while read inputline ; do
        line="${inputline%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%\|*([!|])}"
        line="${line%%*([!|])}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line#*([!|])\|}"
        line="${line##*([!|])}"
        if [[ "$line" != \|*([!|@])@*([!|@])\| ]] ; then
                echo error: "$inputline" 
                ((errors=errors+1))
        fi
done
((errors)) && echo $errors total errors
exit $(($errors!=0))

# 5  
Old 08-07-2003
Thanks for your help - like I said my knowledge of scripting is very meager...

How would I go about setting it up to accept the input file to read through it? ie so I can call the shell script and feed it the name of the file to check as input?

Brian
# 6  
Old 08-07-2003
Put those lines in file called checker or something. Get them exactly right. Close doesn't count. Then make it executable:
chmod u+x checker
Then run it:
./checker < inputfile
# 7  
Old 08-07-2003
MySQL

Thanks for your help, it runs like a champ!

Brian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validating the file

Hello All, I have the following file. The first column is Type. Always the file will have one H and one T type in between all D type reocrds. Need todo some validations. H|ABCD D|TAB N0003107809CD2013-11-14|RYAN|FRY|7 DR|RICHMOND HILL|GA|32431|X|C95|000009999|000000001|TAB||C0001 D|TAB... (3 Replies)
Discussion started by: karumudi7
3 Replies

2. Shell Programming and Scripting

urgent: Not able to send the html formatted message from mailx

<html> <body style=background-color:AliceBlue> <p>Hi,<pre>please check the connectivity status of the server. <pre> And find the server log file for more details. </p> <h1><font size="4">SERVER <font color="red">111.111.11.1</font> IS NOT AVAILABLE IN ONLINE</font></h1> <font color="red"... (5 Replies)
Discussion started by: jothi basu
5 Replies

3. Shell Programming and Scripting

awk for validating

HI, I am trying to write a validation script as below awk '($1=="ABC"&&$2="XYZ" ,then check the value in $8,$10 these columns should not be null. so their should be some corresponding value n the $8 and $10 column,if their is no value the script has to give error saying that at a... (2 Replies)
Discussion started by: gaur.deepti
2 Replies

4. UNIX for Dummies Questions & Answers

Validating a file

Pardon my ignorance but I am lost on how to do this I have a file called "Sample.txt", it is pipe delimited, it should have 13 fields. But some of the records do not, I would like to set up a shell script where I can pass in a parameter "Sample.txt" and it would split the file into records... (2 Replies)
Discussion started by: dgeehot
2 Replies

5. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

6. UNIX for Advanced & Expert Users

Mutt - Word Document or Formatted text as a Message

Hi, I am writing a mailing script by using mutt command. I that i have facing a issues. because, i want to send Some Formatted text as the mail message. but, i try to send the Word Document file as the Mail message. it shows some junk characters in the mail. :confused:I think the mutt command is... (1 Reply)
Discussion started by: krsenkumar
1 Replies

7. Shell Programming and Scripting

validating data

I have a file like the following aaaaa00005bbbbb aaaaa00108bbbbb The code "00005" and "00108" need to be validated and the list of valid codes are stored in a database. While I loop through the file, should call a sql statement for every records to do the validation? or is... (1 Reply)
Discussion started by: joanneho
1 Replies

8. Shell Programming and Scripting

validating 10. IP address any way possible

HELP: validating IP addresses any way possible -------------------------------------------------------------------------------- I am trying to validate input from the user in a script. I thought is was easy to do using regular expressions but I can't figure out how to use REs in a... (1 Reply)
Discussion started by: nrodolfich
1 Replies

9. Shell Programming and Scripting

Validating $1 and $2 before using

Hi there, I'm trying to validate my $1 and $2 before I use them in the sqlplus update, I think I have the validation rules set correctly??? however when I test my script, it jumps straight into the sql. It doesn't seem to validate the vars....even when I know they are incorrect. if ; then ... (6 Replies)
Discussion started by: nhatch
6 Replies

10. UNIX for Dummies Questions & Answers

validating userid

What's wrong with this syntax? It's part of my 'if' statement but it doesn't seem to pass and it keeps going to the 'else' part. I thought it says that userid must start with a non-numeric character and is between 6 and 10 characters long (alphanumeric). $userid|grep -Eq '^?\{6,10\}+$' if... (2 Replies)
Discussion started by: giannicello
2 Replies
Login or Register to Ask a Question