Validating fixed length field...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Validating fixed length field...
# 8  
Old 05-09-2003
I tried the quotes but that didn't do it. I guess no big deal. I found an alternate way of doing it which I'm not totally happy with... but I'm using awk to split the records, attach a delimiter after each field, like a '/' and then process the 'new' file with the delimiter again via the exec/read command. This works but if the user already typed '/' in the file then it might give me some grief which I'll deal with later. In this case any character, '\/|& @#& blanks *', is valid so I have to pick a delimiter that would most likely be least used...

Thanks to everyone for helping out. I know now that the read command always ignores spaces and concatenate contiguous spaces to a single space.

by the way, why doesn't this work given my premise that any of these characters are valid (+-\/ )...?

echo $desc | grep -Eq '^[0-9a-zA-Z+\-\/][0-9a-zA-Z+\-\/][0-9a-zA-Z ]{2,50}$'

The department description gets flagged as soon as it hits this condition.

Gianni
# 9  
Old 05-10-2003
Nevermind. I finally read up on egrep and grep from the man pages and everything I wanted to know is in there for what I wanted to do.

Searching previous posts also helped me to figure out stuff so thanks to everyone.

Gianni
# 10  
Old 05-21-2003
This new format website doesn't work with Netscape 4.7?Everything was jumbled up.

Just an fyi. Don't use the grep command to do this 'comparison' check (last post). It was only an experiment. You can do the same with an if-then statement.

I found that when I converted all my grep statements to a straight if-then syntax, I could validate 1000 records in maybe 4 seconds...When I left it as a grep comparison, the way I initially coded the program, it took a very long long time....up to 5 minutes depending on the number of records I had to validate.

I was just experimenting with the grep command and thought it may help but it was worse. Thought I'd just share this thought w/everyone.

Gianni
# 11  
Old 05-21-2003
Not sure why it looked funky in netscape 4.7 - I just tried it and it looks fine, at least in the silk road skin..

This thread started out talking about how to read every line from a file and split each one into several parts and store each part in a separate variable, but the last few posts have been about finding certain lines in a file using the grep command..

I'm just curious what you're trying to do with the grep command and if-then statements...
# 12  
Old 05-22-2003
My comment about the Netscape 4.7 is valid though. It looks fine but when you hit 'New Reply', this box ("Your Reply") is a tiny little square in the corner of area and all the buttons for the vB Code are lined up along the edge in that area...weird. I would always have to flip to IE to be able to type any replies.

In any case, my test was to see if grep would be better at handling certain tests for 'existence' and it was definitely slower.

As I started to remove the grep and replace the validation with an if-then statement, my script would finish faster and faster until it just seemed to scroll by/dump the results instanteously...

I changed lines like below. I have many other test conditions that are not this simple, but this is an example:

echo $catcd | grep -Eq '^[[:digit:]][[:digit:]][[:digit:]]$'
if [[ $? -ne 0 ]]; then
...
fi

to:

if [[ $catcd != +([0-9]) ]]; then
..
fi

Your point is valid and that's why I didn't continue this post because you guys answered my questions about the reading of the records, etc. I just wanted to revisit this post to say the thing about the Netscape and tell everyone what I found in my little test. I was surprised at the difference in time of execution (between 3-4 seconds to 5-8 minutes for 1000 records) between grepping and just using an if-then in this case, that's all. I didn't think the time would be so far apart. It was almost 1 sec for each record to be validated in some cases...

Gianni
# 13  
Old 05-22-2003
Avoiding external programs is the the key to fast shell scripts. Even if you need several statements to eliminate the use of an external program, it is almost always a win.

I am typing this reply on an NT system using Netscape 4.7 and I don't see any problem. My work PC is wimpy and I prefer to use Netscape 4.7 where I can because it does not require a lot of resources. I do have my style set to "vbPortal". Maybe you just need another style setting?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies

2. Shell Programming and Scripting

Make it to fixed length

Hi Team, I have a different length records in my text file.I would like to make all the records with same length. I want to check the maximum lenth and all other records make the same length It's urgent request. Thanks in Advance (2 Replies)
Discussion started by: Anthuvan
2 Replies

3. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

4. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

5. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. UNIX for Dummies Questions & Answers

Validating input based on fixed number of fields

Yes, i did... let me state my problem in more detail Inputs: I have one input CSV file And, i have stored no. of comma each line should in a variable. e.g. $ cat cmt.csv this, is a ,comma ,count test1 ,,this, is a ,comma ,count test2 this, is a ,comma ,count test3... (6 Replies)
Discussion started by: Dipali
6 Replies

7. Programming

parsing fixed length field with yacc/bison

How to specify the token length in a yacc file? sample input format <field1,data type ans,fixed length 6> followed by <field2,data type ans,fixed length 3> Example i/p and o/p Sample Input: "ab* d2 9o" O/p : "Field1 Field2 " yacc/bison grammar: record :... (1 Reply)
Discussion started by: sungita
1 Replies

8. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

9. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

10. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question