AWK (NAWK) and filtering values


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

it works with input file :

[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

but doesn't if the input file contains more than 3 fields like the following :

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

we get :

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

i don't understand why !

regards
Christian
# 9  
Old 04-22-2008
The previous script checks the number of fields and assumed that the last field is the timefield so it won't work if you increase this number.
Try this one:

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

Regards
# 10  
Old 04-22-2008
Thanks ,

well it doesn't work :

cat csl2.txt

[565342:00002-00001] 17/04/2008 06:17:09 sfsfsfsfsfsdfsfsf mgfmlgkjgmldskj
> [565342:00002-00001] 17/04/2008 06:17:09 fsfsfsdfdsfsfdsfsf mdfjdsmlfls
[983254:00002-00001] 17/04/2008 00:00:02 sfsfdsfdsfdsfdsf sfldsjfldskfjslkfj
> [983254:00002-00001] 17/04/2008 00:00:02 sfdsfdsfdsfdsfs lkgfjdslksjdfl

awk '/^>/ && substr($4,1,2) > "05" {print;next} substr($3,1,2) > "05" {print}' /users/notes01/csl2.txt

[565342:00002-00001] 17/04/2008 06:17:09 sfsfsfsfsfsdfsfsf mgfmlgkjgmldskj
> [565342:00002-00001] 17/04/2008 06:17:09 fsfsfsdfdsfsfdsfsf mdfjdsmlfls
> [983254:00002-00001] 17/04/2008 00:00:02 sfdsfdsfdsfdsfs lkgfjdslksjdfl

the lines may begin with "[" whether "> "

i still have line with "00" hour

it's just an extract of the input file which is more than 100Mo long

regards

Christian
# 11  
Old 04-22-2008
Oops, forgot something, this should do it:

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

Regards
# 12  
Old 04-23-2008
Bug

Hi ,

it sems to work as i want to do , so thank you very much for your help !

regards
Christian
 
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