Filter file with condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter file with condition
# 1  
Old 09-07-2016
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
Code:
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.
Code:
3246354401 1
3290753729 5 4
3292553369 1 1 1 4

Thanks for your advise.
# 2  
Old 09-07-2016
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.
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 09-07-2016
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.
# 4  
Old 09-07-2016
Hello jiam912,

Could you please try following.
Code:
awk '{for(i=2;i<=NF;i++){if($i==3){next}};print}'  Input_file

Output will be as follows.
Code:
3246354401 1
3290753729 5 4
3292553369 1 1 1 4

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-07-2016
An alternate with an expression:-
Code:
grep -Ev " 3 | 3$" file

or
Code:
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
# 6  
Old 09-07-2016
Here another solution without iterating through all NF but using the field separator:
Code:
$ 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 Smilie

cheers
zaxxon
These 5 Users Gave Thanks to zaxxon For This Post:
# 7  
Old 09-07-2016
Thanks a lot to all.
Dear zaxxon.
Noted I will.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter duplicate records from csv file with condition on one column

I have csv file with 30, 40 columns Pasting just three column for problem description I want to filter record if column 1 matches CN or DN then, check for values in column 2 if column contain 1235, 1235 then in column 3 values must be sequence of 2345, 2345 and if column 2 contains 6789, 6789... (5 Replies)
Discussion started by: as7951
5 Replies

2. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

3. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

4. UNIX for Dummies Questions & Answers

Help me to filter a file

I want to view a file ignoring mutilple comment line (/*....*/). Please help me on this. Advance thanks.:b: (5 Replies)
Discussion started by: Pradipta Kumar
5 Replies

5. Shell Programming and Scripting

Help with awk, using a file to filter another one

I have a main file: ... 17,466971 0,095185 17,562156 id 676 17,466971 0,096694 17,563665 id 677 17,466971 0,09816 17,565131 id 678 17,466971 0,099625 17,566596 id 679 17,466971 0,101091 17,568062 id 680 17,466971 0,016175 17,483146 id... (4 Replies)
Discussion started by: boblix
4 Replies

6. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

7. Shell Programming and Scripting

Apply condition on fixed width file and filter records

Dear members.. I have a fixed width file. Requirement is as below:- 1. Scan each record from this fixed width file 2. Check for value under field no "6" equals to "ABC". If yes, then filter this record into the output file Please suggest a unix command to achieve this, my guess awk might... (6 Replies)
Discussion started by: sureshg_sampat
6 Replies

8. UNIX for Dummies Questions & Answers

Filter file according to pattern

Hello I have an input file which is tab delimited.In my unix script I have search for a particular pattern.If it is NOT present then I have to write in an output file. Eg.Input file is : 123 hello 7779 hi hkjh88 hahah 678 hello 90845 ti hkjsdfh 9324 And the search string is "123... (2 Replies)
Discussion started by: akashtcs
2 Replies

9. Shell Programming and Scripting

Filter the column and print the result based on condition

Hi all This is my output of the some SQL Query TABLESPACE_NAME FILE_NAME TOTALSPACE FREESPACE USEDSPACE Free ------------------------- ------------------------------------------------------- ---------- --------- ---------... (2 Replies)
Discussion started by: jhon
2 Replies

10. Shell Programming and Scripting

File filter

Hi Everyone , have a nice i would need a little help on this i have file which contains blocks such as given below <hgsdp:msisdn=923228719047,loc; HLR SUBSCRIBER DATA SUBSCRIBER IDENTITY MSISDN IMSI STATE AUTHD 923228719047 410072110070614 CONNECTED ... (3 Replies)
Discussion started by: Dastard
3 Replies
Login or Register to Ask a Question