AWK (NAWK) and filtering values


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK (NAWK) and filtering values
# 1  
Old 04-21-2008
Tools AWK (NAWK) and filtering values

Hi ,

i try to filter input file :

[565342:00002-00001] 17/04/2008 06:17:09
[983254:00002-00001] 17/04/2008 00:00:02

keeping lines with hour > 06

as :

[565342:00002-00001] 17/04/2008 06:17:09

i tried :

CSL=06

nawk -v CSL="${CSL}" -F'[ :]' '/^\[/ { if ( $4 -gt $CSL) print $0 } ; /^\>/ { if ( $5 -gt $CSL) print $0 }' input_file.txt

i would here give CSL as shell variable

the ouput file is the same as input.

somebody can remove the straw in my eye ?

regards
Christian
# 2  
Old 04-21-2008
Try this:

Code:
awk 'substr($3,1,2) > "06" {print}' file

Regards
# 3  
Old 04-21-2008
Thanks ,

The corrrect statement is :
substr($3,1-2) > "06" {print}

but now i need to put it in my complete AWK command with $CSL , test with first character "[" or ">" and so on , and there is a mistake with the brackets.

can you have a closer look , please ?

Christian
# 4  
Old 04-21-2008
Post your script, the exact content of your input file and the desired output.

Regards
# 5  
Old 04-21-2008
input file like this :

[565342:00002-00001] 17/04/2008 06:17:09
>[565342:00002-00001] 17/04/2008 06:17:09
[983254:00002-00001] 17/04/2008 00:00:02

output file (only the lines where hour > 06 ):

[565342:00002-00001] 17/04/2008 06:17:09
>[565342:00002-00001] 17/04/2008 06:17:09

i would have the "06" value as parameter named CSL
and the first character of the line could be "[" or ">"

and the code i tried is :

nawk -v CSL="${CSL}" -F'[ :]' '/^\[/ { if ( $4 -gt $CSL) print $0 } ; /^\>/ { if ( $5 -gt $CSL) print $0 }' input_file

thanks in advance
Christian
# 6  
Old 04-21-2008
Sorry there is a blank just after the ">" :

[565342:00002-00001] 17/04/2008 06:17:09
> [565342:00002-00001] 17/04/2008 06:17:09
[983254:00002-00001] 17/04/2008 00:00:02

output file (only the lines where hour > 06 ):

[565342:00002-00001] 17/04/2008 06:17:09
> [565342:00002-00001] 17/04/2008 06:17:09

regards
Christian
# 7  
Old 04-21-2008
I suppose you mean the lines with hour > 05:

Code:
awk '
NF==3 && substr($3,1,2) > "05" {print;next}
substr($4,1,2) > "05" {print}
' file

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Filtering based on column values

Hi there, I am trying to filter a big file with several columns using values on a column with values like (AC=5;AN=10;SF=341,377,517,643,662;VRT=1). I wont to filter the data based on SF= values that are (bigger than 400) ... (25 Replies)
Discussion started by: daashti
25 Replies

2. Shell Programming and Scripting

Filtering values in variable

Hi, is there a faster/simpler way to filter values from the variable1 in variable2? example: variable1="A|B|C|E" variable2="A|B|C|D|F" output: "A|B|C" Thanks, zzavilz (4 Replies)
Discussion started by: zzavilz
4 Replies

3. Shell Programming and Scripting

Filtering my major and minor values

I want to remove all rows with a minor repeating count less than 30% compared to the major repeating count from my table. The values of a col(starting col 2) can assume is A,T,G,C and N. Each row has at least 2 values and at most 4 repeating values(out of ATGC). N is considered a missing value... (12 Replies)
Discussion started by: newbie83
12 Replies

4. Shell Programming and Scripting

Perl: filtering lines based on duplicate values in a column

Hi I have a file like this. I need to eliminate lines with first column having the same value 10 times. 13 18 1 + chromosome 1, 122638287 AGAGTATGGTCGCGGTTG 13 18 1 + chromosome 1, 128904080 AGAGTATGGTCGCGGTTG 13 18 1 - chromosome 14, 13627938 CAACCGCGACCATACTCT 13 18 1 + chromosome 1,... (5 Replies)
Discussion started by: polsum
5 Replies

5. Shell Programming and Scripting

Filtering issues while using nawk

Hi, I am currently filtering a file that has multiple sets of data. An example of some of the data is as follows; Sat Oct 2 07:42:45 2010 01:33:46 R1_CAR_12.34 Sun Oct 3 13:09:53 2010 00:02:34 R2_BUS_56.78 Sun Oct 3 21:11:39 2010 00:43:21 R3_TRAIN_COACH_90.12 Mon Oct 4... (1 Reply)
Discussion started by: crunchie
1 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

7. Shell Programming and Scripting

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

8. Solaris

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

9. Shell Programming and Scripting

is it possible to pass external variable values to nawk?

Dear friends, please tell me how to pass the external variable values to the nawk command. length=`expr $len2 - $len1` i need to pass $length to following nawk command as mentioned below. nawk '{if((x=index($0,"W/X"))>0){id=substr($0,x, $length);print x;print id;}}' filename1 but I am... (1 Reply)
Discussion started by: swamymns
1 Replies
Login or Register to Ask a Question