How to use awk command(file) with file command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use awk command(file) with file command?
# 1  
Old 06-28-2013
How to use awk command(file) with file command?

how can i call awk file "average.awk" (code as follows) with file commands like ls -s...
Code:
#!/bin/awk -f
BEGIN {
# How many lines
    lines=0;
    total=0;
}
{
# this code is executed once for each line
# increase the number of files
# lines++;
# increase the total size, which is field #1
        if ($1 != "total" ) lines++;
    total+=$1;
}
END {
# end, now output the total
    print lines " lines read";
    print "total is ", total;
    if (lines > 0 ) {
        print "average is ", total/lines;
    } else {
        print "average is 0";
    }
}

# 2  
Old 06-28-2013
You can simply pipe the output of your command:
Code:
command | average.awk

# 3  
Old 06-28-2013
Code:
ls -l | awk -f average.awk

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

2. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

3. Shell Programming and Scripting

Split a file using awk command.

awk 'FNR == 1 { c = 1 } { print > (f c) } !FNR%n { close(f c); ++c }' n=$files_per_stream f=$input_path/filename_ $input_file $input_file with some records are splitted into files named filename_1,filename_2...etc according to $files_per_stream. Plz help me know how and if anyone has... (7 Replies)
Discussion started by: guptam
7 Replies

4. 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

5. Shell Programming and Scripting

Awk command to split file name

Hi I have few files with format access.2Nov-12:15AM. These files will be generated daily . I need to write a script so that if today's date is less than 10 then it has to zip the file and rename it to acess.02Nov-12:15AM.gz .please help me in this . Also please help me in splitting the file... (10 Replies)
Discussion started by: mskalyani9
10 Replies

6. Shell Programming and Scripting

Using awk command for .csv file

Hi , I have .csv file with value separated by ";". 1. Using awk how to extract perticular colums and store in to array 2. For some columns I needs to extract last value of the column How to do same please help me ASAP Thanks and Regards, Sushma (9 Replies)
Discussion started by: sushmab82
9 Replies

7. Shell Programming and Scripting

awk command to test if a string is a file

What awk command will test a string to determine if it is a valid file name? With the following awk statement I isolate the lines from the inputfile that might contain a filename, then I attempt to test the possible filename which is always in $4 from each line. However it is not working at all... (4 Replies)
Discussion started by: Arsenalman
4 Replies

8. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. Shell Programming and Scripting

retrive lines from a file using AWK command

Dear friends, please tell me how to get some required lines from a file and write to another file using AWK command. i.e., if a file contains, abcdefghigk 12345 lmnopqrstuv 678910 wxyz please tell me how to get lines(line count is always 2 and it's contineous) mentioned in blue... (1 Reply)
Discussion started by: swamymns
1 Replies
Login or Register to Ask a Question