I have a pattern which look like this:
2 20080219_21:43:22.194 ISC-Libya Belgium1 24 IAM 20115139248 218913265641 b 11672 ACM b 20614 CPG b 20619 CPG b 20626 CPG f 33925 REL b 34215 RLC :COMMA: NCI=00,FCI=6001,CPC=0A,TMR=00,USI: :COMMB: BCI=0201: :RELCAUSE:10:
2 20080219_21:43:40.277 ISC-Libya Belgium1 57 IAM 20111329078 218923547827 b 9365 ACM f 15907 REL b 16184 RLC :COMMA: NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB: BCI=0434,OBI=01: :RELCAUSE:10:
These patterns have number of fields ($NF) , i want a script that if finds the number of fields inside a certain pattern greater than 30 it delets the whole pattern ?
The Second Requirement :
For $7 and $8 the field begins with a country code say (44) so i want a script which adds additional field according the country code found in $7 and $8.
So the Pattern will be the same but only i will have additional field containing country code of both $7 and $8.
For sure the field which will be added to the pattern will be the country name which is according to the country code of $7 and $8 so in the last example as you may see you will find county code (20) so this will be Egypt and 218 which is country code of Libya
I have a pattern which look like this:
2 20080312_10:55:35.800 Spain-Telefonica ISC 9 IAM 927535957 34670505334 f 275 COT b 700 ACM b 6577 CPG b 10726 ANM b 202195 REL f 202307 RLC :COMMA: NCI=15,FCI=2101,CPC=0A,TMR=00,USI,OFI=00: :COMMB: BCI=0214,OBI=01,ACT: :RELCAUSE:10:
This Pattern has number of fields = NF and at the same time there are large number of patterns like this.
What i want is a script that if it finds NF which is the number of fields greater than 30 it delets the whole pattern till $NF.
Some patterns are placed in a file named CDR.date1
Another files are placed in another file named CDR.date2
and so on.....
Please Ignore the first requirement regarding the country codes my second problem can be explained as follows.
I have a group of patterns like this :
2 20080324_13:06:31.373 ISC TeleGlobe-Montreal 110 IAM 962795507127 218927119177 f 6 IAM b 3243 REL f 3244 RLC b 3276 REL b 3282 REL f 3284 RLC b 3289 REL f 3294 RLC b 3296 REL b 3302 REL f 3304 RLC b 3309 REL f 3314 RLC b 3316 REL b 3322 REL f 3324 RLC b 3329 REL f 3765 RLC b 3766 REL f 3769 RLC b 3770 REL f 3772 RLC b 3775 REL b 3779 REL b 3783 REL f 3787 RLC b 3787 REL f 3791 RLC b 3792 REL f 3795 RLC b 3796 REL f 3799 RLC b 3800 REL f 3802 RLC b 3805 REL b 3809 REL b 3813 REL b 3817 REL f 3821 RLC b 3822 REL f 3825 RLC b 3826 REL f 3829 RLC :COMMA: NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB:: :RELCAUSE:22:
As shown the number of fields exceeds 30 (NF>30) , and as an information this pattern is one out of another patterns which are inserted in the same file so i want a a script when if finds pattern from this type (NF>30), it deletes it completely
Thanks and please waiting for feedback because it is really very annoying for me
I tried the command you typed to me the reply is :
awk: Input line has too many number of fields and then he writes the input line name !!
i tried using nawk it gives the same answer
The problem is that it stops on the input line which have too much number of fields as i sent you so the idea is in deleting this line when it is found immediately
cat CDR.* | awk '{print NF}' on these lines the output is below
25
18
18
25
18
18
18
18
18
18
22
22
18
22
18
18
awk: record `2 20080324_13:06:33....' has too many fields
record number 16
It seems that AWK can't be done on large number of fields even when i am trying to count the number of fields
Missed the fact that you had tried nawk. That leaves gawk, or you can switch to Perl.
perl -lane 'print 1+$#F' CDR.*
To remove files with more than 30 fields, try this.
perl -lane 'print unless @F > 30'
The $#array construct is zero-based so you have to add one to get the number of fields. @array (in scalar context) returns the actual number of elements in the array, as a natural (one-based) number.
Regarding perl i tried the first command and it returns the number of fields per each line , i even redirected the output to a sperate file so now i have file containing number of fields per each line
When i tried to type the second command whom you say it deletes the lines , it returns nothing i waited long time and no response
The question is how i link your second command to the data (CDR.*); i think i can't get your point
Sorry if i bothered you but anyway the second command didn't work i typed it as you give me it seems to be executing but i wait for a long time and nothing appear or any error message , i don't know what do you mean by giving it bunch of files ?
Pressing CTRL+D up to my knowledge returns you to command line
The first command works and returned number of field per line.