How to use awk to classify file extension from input ls -l


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use awk to classify file extension from input ls -l
# 1  
Old 02-15-2010
How to use awk to classify file extension from input ls -l

i try to do this for a long time
input is command ls -l
and output is:

Code:
Number of files : xx 
Number of file type – awk : 5        total size: 2345 bytes  // file ex type .awk
Number of file type – dat : 10        total size:  233 bytes  // file ex type .dat
...
Number of unknown file type : 20    total size: 9879 bytes // no file type

i try to write awk script because this is my awk's practice
thank for any comment
ps. sorry for my poor english

Last edited by Scott; 02-23-2010 at 07:46 PM.. Reason: Code tags
# 2  
Old 02-15-2010
Hi. I think first you must get the extension and then increment a element in a dictionary. Finally you must print all the elements in dictionary
Code:
{
  #Get the extension and count
  if (match($9, /[^.]*$/)){
    count[substr($9,RSTART,RLENGTH)]++
  }else{
    count["Unknown"]++
  }
}
END{
  #Print all the counters
  for(x in count){
    print "x---"count[x]
  }
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Classify lines in file using perl

The below perl executes and does classify each of the 3 lines in file.txt. Lines 2 and 3 are correct as they fit the criteria for Rule 2. The problem is that line one should be classified VUS as it does not meet the criteria for Rule 1, so Rule 3 is used. However, currently Rule 2 is changing the... (27 Replies)
Discussion started by: cmccabe
27 Replies

3. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

5. Shell Programming and Scripting

AWK to classify a file into several ones ..

Good Day All, I need to make a script that will do the following : 1- read a .csv file line by line, check the 3 field of each file print the whole line if this field matches the condition (note : FS = ",") 2-from the basic file, the script should genrate 3 new files based on the step #1... (6 Replies)
Discussion started by: engkemo2002
6 Replies

6. Shell Programming and Scripting

awk- reading input file twice

Hello, I've been trying to come up with a solution for the following problem; I have an input file with two columns and I want to print as an output the first column without any changes but for the second column, I want to divide it by its last value. Example input: 1 9 2 10 3 11 4 12 5... (14 Replies)
Discussion started by: acsg
14 Replies

7. Shell Programming and Scripting

Awk command without input file

i have a requirement to compare two time stamps in IF condition and return true whenever the second timestamp is greater than first, i will also be checking, if the timestamp in HHMMSS format( 6 digit time stamp ).Im able to achieve it using awk, however i dont want to give any input file to awk... (3 Replies)
Discussion started by: saikiran_1984
3 Replies

8. Shell Programming and Scripting

awk and regex to find out file extension

From following data, I want to only publish those lines in which column 6 has the value with extension .dat. col1,col2,col3,col4,col5,col6.txt,col7,col8 col1,col2,col3,col4,col5,col6.date,col7,col8 col1,col2,col3,col4,col5,col6.jpg,col7,col8 col1,col2,col3,col4.dat,col5,col6.dat,col7,col8... (3 Replies)
Discussion started by: fahdmirza
3 Replies

9. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

10. Shell Programming and Scripting

stripp extension from file and use as input....

trying to evaluate some files.... synopsis": list all files with .xml ext.....remove the .xml ext... then use the file without the .xml ext and pass through two style sheets...one returning the filename with .xml ext and the other returning filename with .OK got errors........ (4 Replies)
Discussion started by: jazz21
4 Replies
Login or Register to Ask a Question