Capturing the invalid records to error file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing the invalid records to error file
# 1  
Old 05-04-2011
Capturing the invalid records to error file

HI,

I have a source file which has the below data.

Code:
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
Tableid,table.txt
sourceid,1,2,3,4,5,6
targetid,1,2,3,4,5,6

My target should be

Code:
Tableid,table
sourceid,2,3,4,5,6
targetid,2,3,4,5,6
Tableid,table
sourceid,4,5,6
targetid,4,5,6

I am trying to capture all the tableids with no .txt extension .

Any ideas please.

Thx,Shruthi

Last edited by joeyg; 05-04-2011 at 09:53 AM.. Reason: Please wrap scripts and data inside CodeTags
# 2  
Old 05-04-2011
Why is 1 missing for the 1st occurence and why is 1,2,3 missing for the second?
# 3  
Old 05-04-2011
That was a sample data, below data will be clear.

source data
Code:
Tableid,table.txt
sourceid,ods,edw,edwh
targetid,ods,edw,edwh
Tableid,table
sourceid,ods,edw,edwh
targetid,ods,edw,edwh
Tableid,table.txt
sourceid,abc,xyz,abc
targetid,abc,xyz,abc
Tableid,table.txt
sourceid,ods,edw,edwh
targetid,ods,edw,edwh
Tableid,table
sourceid,abc,xyz,abc
targetid,abc,xyz,abc

Target data
Code:
Tableid,table
sourceid,ods,edw,edwh
targetid,ods,edw,edwh
Tableid,table
sourceid,abc,xyz,abc
targetid,abc,xyz,abc

Basically I am trying to do a exception handling..records with no valid extension that whole bunch I am dumping in a error file

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 05-04-2011 at 10:18 AM.. Reason: code tags
# 4  
Old 05-04-2011
Please use code tags in future when posting code, data or logs etc. See my moderator comment in your last post - you also got a PM with a guide, no biggie, please obeye, thanks.

Code:
$> awk '/Tableid,table$/ {print; p=1; next} /Tableid,table.txt$/ {p=0; next} p' infile
Tableid,table
sourceid,ods,edw,edwh
targetid,ods,edw,edwh
Tableid,table
sourceid,abc,xyz,abc
targetid,abc,xyz,abc

# 5  
Old 05-04-2011
Hi,

The table .txt data is dynamic one, here the actual table name will be present( sorry if my sample data is confusing)

I executed the below code..,may be because the table is hardcoded it has not returned any thing.
Code:
awk '/Tableid,table$/ {print; p=1; next} /Tableid,table.txt$/ {p=0; next} p' infile

can we do a substring like $2== doesnot contain .(dot) then consider it.

Thx,shruthi

Last edited by zaxxon; 05-04-2011 at 11:02 AM.. Reason: code tags
# 6  
Old 05-04-2011
Take a second to test out how code tags work; there is also a preview option before you submit your post. It seems you did not read the PM you got nor the short moderation notices inside your posts, nor what I wrote in my post.
There is also a button up there in the editing window to put something into code tags.
Just writing code: does not work. The forum software can't interpret this.
If you still do not respond on wether you ignore this or do not understand the PM, you will collect infraction points until you get banned from the forum. I doubt you want this to happen, so please obeye this!

Code:
awk '/Tableid,table$/ {print; p=1; next} /Tableid,table\..*$/ {p=0; next} p' infile

# 7  
Old 05-04-2011
Hey,

Sorry for the trouble, I have joined recently in this forum, go forward I will post as per the guide lines.

Thx,Shruthi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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: 12234XYZ TY^4253$+00000-00000........... I need to check is there any control characters(like ^M,^Z) The line will be splitted awk '{id=substr($0,1,5) nm=substr($0,6,3)... (2 Replies)
Discussion started by: dineshaila
2 Replies

2. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies

3. Red Hat

Can't chgrp. Error - chgrp: changing group of `<file>': Invalid argument

I found that I cannot chgrp for some reason with error: chgrp: changing group of `<file>': Invalid argument This happens on all NFS mounted disks on client machines. We use AD (not my call) for authentication and it also provides groups. We have a NFS server running Scientific Linux 6.3... (1 Reply)
Discussion started by: venmx
1 Replies

4. Shell Programming and Scripting

Extract error records based on specific criteria from Unix file

Hi, I look for a awk one liner for below issue. input file ABC 1234 abc 12345 ABC 4567 678 XYZ xyz ght 678 ABC 787 yyuu ABC 789 7890 777 zxr hyip hyu mno uii 678 776 ABC ty7 888 All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Discussion started by: ratheesh2011
7 Replies

5. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

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

7. Shell Programming and Scripting

01.30 Invalid shell error

Hi, I am getting the error 01.30 Invalid shell error I am running the bash shell script in the korn login shell. I have mentioned the #!/bin/bash statement in the my script but not sure why it is giving this error to me.. (4 Replies)
Discussion started by: mr_harish80
4 Replies

8. Shell Programming and Scripting

Capturing multi-line records containing known value?

Some records in a file look like this, with any number of lines between start and end flags: /Start Some stuff Banana 1 Some more stuff End/ /Start Some stuff End/ /Start Some stuff Some more stuff Banana 2 End/ ...how would I process this file to find records containing the... (8 Replies)
Discussion started by: cs03dmj
8 Replies

9. Shell Programming and Scripting

Error while appending records to a file

Hi, I have a sample file which contains records. Input File : 1 user1 username1\password@database-name 2 user2 username2\password@database-name 3 user3 username1\password@database-name I should search for a 'username1\' in those records. If 'username1\' is found in those records, that record... (7 Replies)
Discussion started by: siri_886
7 Replies

10. 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
Login or Register to Ask a Question