validate each field in txt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting validate each field in txt
# 1  
Old 07-26-2007
validate each field in txt

Hello,

I have a file with a lot of record like below:

00001,CUSTR,CUSTOMER ADDRESS,02310,N,0:00,0,0,0,0,0,0,0,0,0,0,0,0:00,0,0,0,0,0,CSH,ACC

Can I validate each record in the file and output the incorrect result?

field 1 - customer number, should be "5 digit.
field 2 - should be 5 string, no number
field 3 - customer address - any string, number or space
feild 4 - inovice number - should be 5 digit.
field 5 - should be "N' or "Y"
field 6 - process time, should be "mm:ss"
field 7 to 17 - digit
field 18 - end process time, should be "mm:ss"
field 19 to 23 - digit
field 24 - 3 string (A to Z)- no blank, no "?"
field 25 - 3 string (A to Z) - no blank

Here is error sample:
00001,CUSTR,CUSTOMER ADDRESS,023a0,N,1,0,0,S,0,0,0,0,0,0,0,0,12:15,0,0,0,0,0,?,

the error report will look like:
record1:field 4,field 6,field9,field24,filed25

thx!!
# 2  
Old 07-27-2007
change time format

hello,

I have a record below and would like to change the time fromat from m:ss to mm:ss

input
00001,CUSTR,CUSTOMER,02310,N,0:00,0,0,0,0,0,0,0,0,0,0,0,0:00,0,0,0,0,0,CSH,
00001,CUSTR,CUSTOMER,02310,N,5:12,0,0,0,0,0,0,0,0,0,0,0,1:10,0,0,0,0,0,CSH,

output
00001,CUSTR,CUSTOMER,02310,N,00:00,0,0,0,0,0,0,0,0,0,0,0,00:00,0,0,0,0,0,CSH,
00001,CUSTR,CUSTOMER,02310,N,05:12,0,0,0,0,0,0,0,0,0,0,0,01:10,0,0,0,0,0,CSH,
# 3  
Old 07-27-2007
Use perl for this. I think it would be easiest. I don't have access to a test system, so can't give you an example, but basically, read from STDIN, split the line into an array with the ',' as the delimiter. Then use regexes to match your patterns.
# 4  
Old 07-27-2007
Try:
sed 's/,\([0-9]:[0-9][0-9]\)/,0\1/g' data

Assuming "data" is a file with the input.
# 5  
Old 07-27-2007
Both threads are referring to the same problem, so I have merged them. You can follow the same directions, just that when you get to the field with the time, if it is x:xx, just add a leading '0'.
# 6  
Old 07-27-2007
can you provide an example for me?

thx!
# 7  
Old 07-27-2007
anyone can help for this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

4. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

5. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

6. Shell Programming and Scripting

how to add extra a field in a flat txt file ?

Hi all, I did not use UNIX for a long time, now i need to make a flat file with extra field, can you help me with the code ? 1. I create a last line of each log from each system and make it in a flat text file (seperate by a pipe |) mv current.log old tail -1 sanfrancisco.log > current.log... (5 Replies)
Discussion started by: britney
5 Replies

7. Shell Programming and Scripting

gawk help for inserting a field of a .txt file in the same file

i had the following type of data file vchrdump: Vouchers For Date :05/01/2009 * ... (4 Replies)
Discussion started by: KANNI786
4 Replies

8. Shell Programming and Scripting

how to validate a field when it is blank using awk prog

Hi, I tried the below piece of code for my script to check whether it has a blank space for a particular field. if(f10==/]/){ print "Field 10 is Correct";} else{ print "Field 10 is Wrong"; } Please help me to know whether the "if" condition applied here is correct or do i... (14 Replies)
Discussion started by: meva
14 Replies

9. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

10. Shell Programming and Scripting

Reindex or re-increment last field of txt file.

I am using a database text file with a field that increments +1 with each new entry, occasionally if a entry is deleted the unique sequence is disrupted. I am looking for a small script/function in sh and/or perl that would re index this. Example of db file: Name | Address | misc |number... (2 Replies)
Discussion started by: silenthands
2 Replies
Login or Register to Ask a Question

Featured Tech Videos