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

My target should be

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

Why is 1 missing for the 1st occurence and why is 1,2,3 missing for the second?

That was a sample data, below data will be clear.

source data

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

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

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.

$> 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

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.

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

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!

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

Hey,

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

Thx,Shruthi