awk length count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk length count
# 1  
Old 10-11-2012
awk length count

Morning, every one.

I have a file like this:

HTML Code:
AAEQGAGNQPQH	27
AAGETQY	51
AAGGSSYNEQF	12
AAGGYEQY	72
AAGLEAKNIQY	159
AAGPYEQY	26
AAGQDYNSPLH	45
AAGQGGEQF	1587
AAGREGGNTEAF	4
AAGSPQH	3
AAGSYEQY	45
AAGTGAYEQY	19
AAGTSGNNEQF	79
AAGWNTEAF	37
I want to count the string length of the $1 and get the each length's frequency.

This is what I want to get:

HTML Code:
length	No.
12	1
11	4
9	2
8	2
7	3
I use the following code to get one of them:
Code:
awk -F, '{A[length($1)==8] ++} END {for (X in A) print X, A[X] }'  file

# 2  
Old 10-11-2012
Code:
awk '{c[length($1)]++}END{for(i in c) print i,c[i]|"sort -nr"}' file

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 10-11-2012
Code:
awk '{a[length($1)]++} END {for (i in a) print i, a[i]}' OFS='\t' myFile

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to count the length of fasta sequences?

I could calculate the length of entire fasta sequences by following command, awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' unique.fasta But, I need to calculate the length of a particular fasta sequence specified/listed in another txt file. The results to to be... (14 Replies)
Discussion started by: dineshkumarsrk
14 Replies

2. UNIX for Dummies Questions & Answers

Count on grep for more than two values in a row of fixed length file

I want to get count on number of records in a few folders by running grep command for more than two columns in a row of fixed length file. suppose if i have a fixed length file has 5 columns and I want to see the record counts for country =can and province = bc and time stamp <= 12 feb 2013... (14 Replies)
Discussion started by: princetd001
14 Replies

3. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

4. Shell Programming and Scripting

awk get length of a binary file.

Hi.. Just got a problem with awk and cannot figure out whats the issue. I am not really expert in awk so looking for help/opinion from experts Command is $ cat abinaryfile | sed -e "s/@@//g;s/@$//" | awk ' begin {} { printf(length($0)); }' Well its a binary file and I am... (3 Replies)
Discussion started by: iffarrukh
3 Replies

5. Shell Programming and Scripting

how to count string length?

Hi, Gurus, I have a requirement which need count string length. eg. abc bcde defge want to get following: abc 3 bcde 4 defge 5 :wall: thanks in advance! (6 Replies)
Discussion started by: ken002
6 Replies

6. Shell Programming and Scripting

Count line Length

I am trying to write a shell scrip that can give me the line length of a record that was in EBDIC and then converted to ASCII. Everything I try reports 1 yet the length is 2000+. I have tried echo "Line length : ${#FILE}" echo "FILE" |awk -F, '{print NF}' awk '{lenth(file)}' All I can... (11 Replies)
Discussion started by: wbshrk
11 Replies

7. Shell Programming and Scripting

AWK limit for (length) function?

I am trying to use the following code: awk '{s=$0;if(length(s) < 750){getline; s=s " " $0}printf("%s\n",s)}' filename but an error shows that 'awk' is too long. Is there a limit to the awk length function? and what could be an alternate solution for long fixed width records? The code... (3 Replies)
Discussion started by: CKT_newbie88
3 Replies

8. Shell Programming and Scripting

Checking the length using awk??

I have following data in a file a.txt HELLO123456789 HELLO098765432 HELLO322366565 HELLO2343435 HELLO45343 I have to filter those lines whose length is not equal to 14 using awk. Thanks in advance:b: (1 Reply)
Discussion started by: nohup
1 Replies

9. Shell Programming and Scripting

AWK record length fix

Hi Friends, Need some help in AWK. Working on AIX 5 Have been trying the following functionality to make the record length fixed: if( length(record) < 300 ) { printf("%-300s\n", record); } In my opinion it will apply some fillers in the end. Its is not making any... (4 Replies)
Discussion started by: kanu_pathak
4 Replies

10. UNIX for Dummies Questions & Answers

How to count the string length

Please can anyone tell me, how to count the string length (2 Replies)
Discussion started by: Anshu
2 Replies
Login or Register to Ask a Question