Field value check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Field value check
# 1  
Old 05-20-2014
Field value check

used below command to redirect records having P000 in all columns except 4th one in the below files with 3 records , lets say outout in below file is record 1,2 not 3 which is having P000 in the 4th column
below commad not working , any help ?
Code:
awk 'NF>0 { for(i=11;i<=NF;i+=1) if (i!=4 && $i!="P0000*") next }1' File_1.txt

$ cat File_1.txt

S_003   P_003   S_006   P_006   S_008   P_008   
74.9    P0001111   59.6    0.061   72.2    0.002 
96.2    0.003   89.4    P0001111   106.9   0.000

# 2  
Old 05-20-2014
Not quite sure I am understanding what you want to achieve.
Is that what you want?
Code:
awk '/P000/ {if( $4 !~ /P000/)print}' File_1.txt

# 3  
Old 05-20-2014
This may be true to get records of having P000 but i want records of not having..or valid ones. remaining records from the above commands.

Code:
S_003   P_003   S_006   P_006   S_008   P_008
74.9    C0000   59.6    0.061   72.2    0.002
96.2    0.003   89.4    C0000   106.9   
$ awk '/C000/ {if( $4 !~ /C000/)print}' File_1.txt

want these records in the command output...

S_003   P_003   S_006   P_006   S_008   P_008
96.2    0.003   89.4    C0000   106.9

# 4  
Old 05-20-2014
Could I ask you to post the real content of File_1.txt with at lest 6 lines?
And then below a real output of the lines you would like to show from those 6 lines after the command is run?
Maybe that way I can be sure of what you would like to have.
# 5  
Old 05-20-2014
Code:
File contents

S_003   P_003   S_006   P_006   S_008   P_008
74.9    C0000   59.6    0.061   72.2    0.002
96.2    0.003   89.4    C0000   106.9   0.000
74.9    C0000   59.6    0.061   72.2    0.002
96.2    0.003   89.4    C0000   106.9   0.000
74.9    C0000   59.6    0.061   72.2    0.002
96.2    0.003   89.4    C0000   106.9   0.000

Output..

S_003   P_003   S_006   P_006   S_008   P_008
96.2    0.003   89.4    C0000   106.9   0.000
96.2    0.003   89.4    C0000   106.9   0.000
96.2    0.003   89.4    C0000   106.9   0.000

# 6  
Old 05-20-2014
Thanks!
Ok, it looks to me that this is what you want.

Code:
awk '$4 ~ /C000/ || NR==1' File_1.txt

Correct me if I am wrong.

Last edited by Aia; 05-20-2014 at 02:03 AM..
# 7  
Old 05-20-2014
looks like you have posted OR , not this way

Its like eliminating records which are having C000 in any other columns except the 4 th column,
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check field value from a file records

I need a script to check the records in a file , if any value match transfer the record in error.txt file. 1- If any of the any field value is NULL(nothing in this field) Record1|Record2|Record3|Record4|Record5|DATE1|DATE2 Example: 11111111|22222222|NULL|12|444|27042018|27042018... (8 Replies)
Discussion started by: vivekn
8 Replies

2. Shell Programming and Scripting

CSV Split field to check multiple codes

Hello, For work i am trying to generate a combined csv file excisting out of 2 other csv files. The problem i am facing is that the first field on both files have multiple values in there which arent always the same. This first field is also the joining part. The layout of the files is as... (16 Replies)
Discussion started by: SDohmen
16 Replies

3. Shell Programming and Scripting

Check a field in a table

I have made a table PRD_WORK_LM.test and it contains one field, ctrl_test. This field contains a 0 or a 1. I want to write a unix script that goes like this: IF ctrl_test = 1 THEN ... ELSE exit FI How can I write this in a script? Do I have to do this within bteq? or outside bteq? can... (5 Replies)
Discussion started by: katled
5 Replies

4. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

5. Shell Programming and Scripting

perl or awk, field length check

Hi Everyone, 1.txt a;1234;134;1111111 b;123;123;1111111 c;123;1334;1111111 d;1234;1234;1111111 output a;1234;134;1111111 c;123;1334;1111111 d;1234;1234;1111111 if field2 legth>3 or field3 length >3, then output. Please advice. Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

6. Shell Programming and Scripting

simplify the script, check field match to value in a file

Hi Everyone, Below is the script, i feel there should be more simple way to do the same output, my one works, but feel not nice. like using index i feel it is slow (image my file is very large), maybe awk can do one line code? Please advice. # cat 1.txt 1 a 2 b 3 cc 4 d # cat 1.pl... (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. Shell Programming and Scripting

avoid open file to check field.

Hi Everyone, # cat a.txt 94,aqqc,62345907, 5,aeec,77, # cat 1.pl #!/usr/bin/perl use strict; use warnings; use Date::Manip; open(my $FA, "/root/a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\,/, $_); if (index($tmp, "qq") ne -1) { ... (4 Replies)
Discussion started by: jimmy_y
4 Replies

8. Shell Programming and Scripting

check for the value of one particular field and give output in a different file

hi i need to check for the value of one particular field : in the output file. the file may contain many such records as below how to ???? *** Throttled with base name + key params! : : -518594328 : les.alarm.LBS12005 : les.alarm.LBS12005 : les : lessrv1 : les : 2328 : 0... (7 Replies)
Discussion started by: aemunathan
7 Replies

9. Shell Programming and Scripting

awk: How to check if field is blank?

In awk, I'd like to check if a field is blank. And by blank I mean, the field could be "" or " " In other words, the field could either be empty, or be filled with spaces. Would the regex look like this? $5 ~ // { Action }? What other ways are there? Hmm.. in any case I think... (7 Replies)
Discussion started by: yongho
7 Replies
Login or Register to Ask a Question