Filter file with condition

Gents,

I am stuck at end of my process.. I got the following file (input). And I want to filter it, checking from the column 2 to the end of the file.

The condition is if in any column from cl2 to the end exist value 3, not filter, but if there is not value 3, should print all the row(output desired).

input

3246153861 3 3 3
3246154245 3 4
3246353861 3 3
3246354401 1
3246553861 3 3 3 4
3246754459 1 3
3246754581 3 3
3247553117 3 4
3247554017 3 4
3247953057 3 3 4
3247954197 3 3
3248353117 3 4
3248353489 1 3
3289354149 3 3
3290153609 1 3
3290553297 2 3 3 4 4
3290553405 3 4
3290554029 3 3
3290554425 3 3
3290753285 3 4 4
3290753405 1 3
3290753729 5 4
3290953825 3 4
3290954041 3 3
3290954569 3 4
3291153285 3 4 4 4
3291153477 1 3
3291154017 3 4
3292353945 3 3
3292354659 1 3
3292553357 1 3 3
3292553369 1 1 1 4
3292553657 1 3
3292553945 3 3
3293953345 3 4
3294553585 3 6
3295153705 3 4

output desired.

3246354401 1
3290753729 5 4
3292553369 1 1 1 4

Thanks for your advise.

Dear jiam912,

I have a few to questions pose in response first:-

  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

Initial thoughts are that you would need an expression to ignore the first field then catch a 3. Would 23 or 32 be acceptable to match as effectively text, or is it the value 3 that is important here?

Robin

We're all here to learn and getting the relevant information will help us all.

1 Like

Hi rbatte1

prefer too is awk, the value 3 is the import here has this validated the row.
the input I show in my request, is from other process, therefore for the moment I dont have idea how to solve the problem. nothing try yet. I am using debian7

I am working on that.

Hello jiam912,

Could you please try following.

awk '{for(i=2;i<=NF;i++){if($i==3){next}};print}'  Input_file

Output will be as follows.

3246354401 1
3290753729 5 4
3292553369 1 1 1 4

Thanks,
R. Singh

1 Like

An alternate with an expression:-

grep -Ev " 3 | 3$" file

or

egrep -v " 3 | 3$" file

The way I'm looking at it, I want to exclude ( -v flag) the lines matching the expression "space 3 space or space 3 end-of-line"

Does that help/make sense?

Robin

Here another solution without iterating through all NF but using the field separator:

$ awk -F"^[0-9]+ " '$2 !~ /3/' infile
3246354401 1
3290753729 5 4
3292553369 1 1 1 4

@jiam912:
You have 277 posts in the forum so I assume you had a lot of question which people will have answered you. Next time, please provide a try, no matter how wrong it will be but just to show us that you did a little something on your own before posting here :wink:

cheers
zaxxon

5 Likes

Thanks a lot to all.
Dear zaxxon.
Noted I will.