Sponsored Content
Top Forums Shell Programming and Scripting How to get the Invalid records from a file using awk? Post 302972087 by dineshaila on Friday 29th of April 2016 11:21:44 PM
Old 04-30-2016
How to get the Invalid records from a file using awk?

My Input file is fixed length record ends with . as end of the line and the character length is 4156
Example:
Code:
12234XYZ     TY^4253$+00000-00000...........


I need to check is there any control characters(like ^M,^Z)
The line will be splitted
Code:
awk
'{id=substr($0,1,5)
nm=substr($0,6,3)
ad=substr($0,10,5)
ct=substr($0,15,8)

if ( id ~ /^ *$/ )
{
       a1="Invalid Id:EMTPY"
}
if ( id !~ /^[0-z]*$/ )
{
    a2="Invalid Id:"id
}
if ( nm ~ /^ *$/ )
{
     a3="Invalid Name:Empty"
}
if ( nm !~ /^[a-z]*$/)
{   
    a4="Invalid Name:" nm
}
like so on
.
....
if (  id !~ /^[0-z]*$/ || nm !~ /^[a-z]*$/ || nm !~ /^ *$/ || ......)
        {
             print id":record valid"
        }
else
      {
      print id-a1,a2,a3,a4...
 }
}'

the outptut should be
Code:
id-Invalid Name:Empty Invalid ad:@%!^%@! Invalid ct:8889%%

Is there any way to reduce the if conditions.. or the best way to achieve the ouput

Last edited by Scrutinizer; 04-30-2016 at 01:56 AM.. Reason: Corrected and moved code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

2. Shell Programming and Scripting

awk script required for finding records in 1 file with corresponding another file.

Hi, I have a .txt file (uniqfields.txt) with 3 fields separated by " | " (pipe symbol). This file contains unique values with respect to all these 3 fields taken together. There are about 40,000 SORTED records (rows) in this file. Sample records are given below. 1TVAO|OVEPT|VO... (2 Replies)
Discussion started by: RRVARMA
2 Replies

3. UNIX for Dummies Questions & Answers

AWK ??-print for fields within records in a file

Hello all, Would appreciate if someone can help me out on the following requirement. INPUT FILE: -------------------------- TPS REPORT abc def ghi jkl mon pqr stu vrs lll END OF TPS REPORT TPS REPORT field1 field2 field3 field4 field5 field6 (8 Replies)
Discussion started by: hyennah
8 Replies

4. Shell Programming and Scripting

Filter records in a file using AWK

I want to filter records in one of my file using AWK command (or anyother command). I am using the below code awk -F@ '$1=="0003"&&"$2==20100402" print {$0}' $INPUT > $OUTPUT I want to pass the 0003 and 20100402 values through a variable. How can I do this? Any help is much... (1 Reply)
Discussion started by: gpaulose
1 Replies

5. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

6. Shell Programming and Scripting

awk - splitting 1 large file into multiple based on same key records

Hello gurus, I am new to "awk" and trying to break a large file having 4 million records into several output files each having half million but at the same time I want to keep the similar key records in the same output file, not to exist accross the files. e.g. my data is like: Row_Num,... (6 Replies)
Discussion started by: kam66
6 Replies

7. Shell Programming and Scripting

Capturing the invalid records to error file

HI, I have a source file which has the below data. Tableid,table.txt sourceid,1,2,3,4,5,6 targetid,1,2,3,4,5,6 Tableid,table sourceid,1,2,3,4,5,6 targetid,1,2,3,4,5,6 Tableid,table.txt sourceid,1,2,3,4,5,6 targetid,1,2,3,4,5,6 Tableid,table sourceid,1,2,3,4,5,6 targetid,1,2,3,4,5,6... (6 Replies)
Discussion started by: shruthidwh
6 Replies

8. Shell Programming and Scripting

awk script for getting the selected records from a file.

Hello, I have attached one file named file.txt . I have to create a file using the awk script with the records in which 38th position is P and not V . ex it should have 00501 HOLTSVILLE NYP00501 and it should not include 00501 I R S SERVICE CENTER ... (3 Replies)
Discussion started by: sonam273
3 Replies

9. Shell Programming and Scripting

awk - compare records of 1 file with 3 files

hi.. I want to compare records present in 1 file with those in 3 other files and print those records of file 1 which are not present in any of the files. for eg - file1 file2 file3 file4 1 1 5 7 2 2 6 9 3 4 5 6 7 8 9 ... (3 Replies)
Discussion started by: Abhiraj Singh
3 Replies

10. Shell Programming and Scripting

Awk/sed/cut to filter out records from a file based on criteria

I have two files and would need to filter out records based on certain criteria, these column are of variable lengths, but the lengths are uniform throughout all the records of the file. I have shown a sample of three records below. Line 1-9 is the item number "0227546_1" in the case of the first... (15 Replies)
Discussion started by: MIA651
15 Replies
fmod(3) 						     Library Functions Manual							   fmod(3)

NAME
fmod, drem, remainder - Compute the floating-point remainder LIBRARY
Math Library (libm.a) SYNOPSIS
#include <math.h> double fmod (double x, double y); float fmodf (float x, float y); long double fmodl (long double x, long double y); double drem (double x, double y); float dremf (float x, float y); long double dreml (long double x, long double y); double remainder (double x, double y); float remainderf (float x, float y); long double remainderl (long double x, long double y); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: fmod(): XPG4 remainder(): XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. DESCRIPTION
The fmod(), fmodf(), and fmodl() functions return the remainder r = x - n*y, where n = trunc(x/y). The result has the same sign as x and magnitude less than the magnitude of y. The remainder is computed exactly and |r| is less than |y|. The drem(), dremf(), dreml(), remainder(), remainderf(), and remainderl() functions return the remainder r = x - n*y, where n = rint(x/y). Additionally, if |n - x/y|=1/2, then n is even. The remainder is computed exactly and |r| is less than or equal to |y|/2. The drem() and remainder() functions are aliases of each other. The dremf(), and remainderf() functions are aliases of each other. The dreml() and remainderl() functions are aliases of each other. The following table describes function behavior in response to exceptional arguments: --------------------------------------------------------------------------- Function Exceptional Argument Routine Behavior --------------------------------------------------------------------------- fmod(), fmodf(), fmodl() x = infinity Invalid argument fmod(), fmodf(), fmodl() y = 0 Invalid argument drem(), dremf(), dreml() x = infinity Invalid argument drem(), dremf(), dreml() y = 0 Invalid argument remainder() x = infinity Invalid argument remainderf() x = infinity Invalid argument remainderl() x = infinity Invalid argument remainder() y = 0 Invalid argument remainderf() y = 0 Invalid argument remainderl() y = 0 Invalid argument --------------------------------------------------------------------------- delim off fmod(3)
All times are GMT -4. The time now is 08:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy