Verifying Record Length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verifying Record Length
# 1  
Old 05-11-2013
Linux Verifying Record Length

Hi all,

We are going through a total migration from AIX-based server framework to Linux-based servers. When I am testing *.sh and *.awk in a lower environments, it abends at the same step everytime in verifying the record length of the first row of the source file.

I know this source file is good because I pulled the file from the production environment in which the source file was already processed succesfully. So, I'm thinking the existing script (a header checking process) that was pulled from the existing AIX production server. There are two result options for this script: Good or Problem File.

The error always comes back that there is a "Problem with the source file sent". I'm not a scripter as it's not part of my duties, but the task has fallen onto my team. Wondering if the script below is compatible with Linux server syntax?? ANY insight would be greatly appreciated.


BEGIN {
good_count = 0
bad_count = 0
line_count = 0
}
NR == 1 {
rec_count = substr($0, 15, 8)
date_str = substr($0, 32, 10)

print "Date in Header Record : " date_str
}
NR > 1 {
line_count++

if (length($0) == 710)
{
print $0 > GoodFile
good_count++
}
else
{
print $0 > BadFile
bad_count++
}
}
END {
if ( line_count == rec_count && bad_count==0 )
{
print "********************************************"
print "Count in header : " rec_count
print "Count in file received : " line_count
print " "
print "Number of Good Records : " good_count
print "Number of Bad Records : " bad_count
}
else
{
print "********************************************"
print " PROBLEM WITH FILE SENT FROM SOURCE "
print " "
print "Count in header : " rec_count
print "Count in file received : " line_count
print " "
print "Number of Good Records : " good_count
print "Number of Bad Records : " bad_count
exit 99
}
}

# 2  
Old 05-11-2013
HI ,

if u can post the sample of your input file .it would be helpful to debug
# 3  
Old 05-11-2013
Linux

Quote:
Originally Posted by zozoo
HI ,

if u can post the sample of your input file .it would be helpful to debug
Hi zozoo,

I tried pasting the header and 1st row of data but the format didn't show up right, so I'm attaching it. Although the actual 1st record row is displayed in multiple lines in the atachment, it IS on one line in the source file.

I also want to show the logfile for the result of 'verifying record length':

Date in Header Record : 04/22/2013
******************************************** PROBLEM WITH FILE SENT FROM SOURCE
Count in header : 400133
Count in file received : 400133
Number of Good Records : 400133
Number of Bad Records : 0
# 4  
Old 05-11-2013
In the future, please post your source code as a single block inside CODE tags instead of tagging each line of your source code!

There isn't anything immediately obvious to me that is wrong with this awk script file.

I'm assuming that you at least realize that this is an awk script file; not a shell script file. Please show us the exact command line that is being used to invoke awk using this script file and show us how the input file is being passed to awk. Is input coming from a tape drive with variable length records (that the script is then verifying all each contain 710 characters not counting the trailing newline character)?

What Linux system are you using?
What shell are you using on Linux?
What version of AIX are you using on your AIX server?
What shell is being used on your AIX server?
Is the input data file encoded in EBCDIC?
# 5  
Old 05-11-2013
[QUOTE=I'm assuming that you at least realize that this is an awk script file; not a shell script file. Please show us the exact command line that is being used to invoke awk using this script file and show us how the input file is being passed to awk. Is input coming from a tape drive with variable length records (that the script is then verifying all each contain 710 characters not counting the trailing newline character)?

What Linux system are you using?
What shell are you using on Linux?
What version of AIX are you using on your AIX server?
What shell is being used on your AIX server?
Is the input data file encoded in EBCDIC?[/QUOTE]


Hi Don,

Yes, sorry...yes I know it's an awk script based on the extension of the script.

==============
The process that invokes the awk script:

1. Check for source file arrival
2. Header date verified on incoming file from internal sql query to database
lookup table
3. Translate unwanted Characters to spaces
4. Move file from source directory to processing directory

After the above completes, the Verify Record Length AWK script automatically begins.

1. Veryifies total records and checks record lengths
===============

What Linux system are you using? Red Hat Enterprise Linux Server release 5.8 (Tikanga)
What shell are you using on Linux? Korn
What version of AIX are you using on your AIX server? 5.3.0.0
What shell is being used on your AIX server? Korn
Is the input data file encoded in EBCDIC? Do not know.
# 6  
Old 05-11-2013
Should be all in one line:
Code:
if ( line_count == rec_count && bad_count==0 ) {

Dito
Code:
if (length($0) == 710) {


Last edited by MadeInGermany; 05-11-2013 at 04:04 PM..
# 7  
Old 05-11-2013
Hello,

So you're saying to place that one character symbol on the line you showed in your post?

Forgive me, but I am not involved in any scripiting in my job, so I am a bit ignorant. However, through googling trying to figure this out, I am a little more familiar now than I was before.

Question: regarding the "($0)" if (length($0) == 710)
Is this checking ONLY the length of the FIRST record? Not entirely sure what that variable is representing.

Last edited by SoloXX; 05-11-2013 at 04:37 PM.. Reason: question
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Record length

Hi, The record length may be differ in afile. I want to display the records if the record length is not equal to 50 using sed/awk command. Thanks in Advance (6 Replies)
Discussion started by: NareshN
6 Replies

3. Shell Programming and Scripting

Viewing a record of particular length

I have records with different lengths say 386, 387 and 388. Do i have any command to view all the records of the length 386 ? Please do advise. Thanks (2 Replies)
Discussion started by: bobby1015
2 Replies

4. 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

5. Shell Programming and Scripting

Check length of record

Hi, I have a problem, please help me, I have a flat file like this: P00000000088888888999999999 0000999903 000000000000000000 P00000000077777777000000000 0000999903 000000000000000000 P00000000044444444333333333 0000999903 00000000000000000079875 P00000000066666666111111111 0000999903 ... (5 Replies)
Discussion started by: DebianJ
5 Replies

6. 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

7. Shell Programming and Scripting

AWK record length fix

Hi Friends, Need some help in AWK. Working on AIX 5 Have been trying the following functionality to make the record length fixed: if( length(record) < 300 ) { printf("%-300s\n", record); } In my opinion it will apply some fillers in the end. Its is not making any... (4 Replies)
Discussion started by: kanu_pathak
4 Replies

8. UNIX for Dummies Questions & Answers

Creating new file with new record length

Hi there, using the command below > cat file1 | tr "\001" " " > tmp2 how can I alter the record length of tmp2 to fix length of 350 bytes ? Thanks a lot! (7 Replies)
Discussion started by: mrjunsy
7 Replies

9. Shell Programming and Scripting

fixed record length

hello! I have a file with fixed record length... format: 123445asdfg 4343777 sfgg I wanna convert it to 123445,asdfg ,4343,777 ,sfgg is there any way to do it? sed/grep/awk?? at the moment I use sed -e 's_ \(\)_,\1_g' but it works only if there are spaces between... (16 Replies)
Discussion started by: george_
16 Replies
Login or Register to Ask a Question