Sponsored Content
Top Forums Shell Programming and Scripting AWK exclude first and last record, sort and print Post 302576097 by radoulov on Wednesday 23rd of November 2011 03:16:49 PM
Old 11-23-2011
Just to add a reference to the relevant part of the manual:


Quote:
print items | command

It is possible to send output to another program through a pipe instead of into a file.
This redirection opens a pipe to command, and writes the values of items through this pipe to another process created to execute command.
The redirection argument command is actually an awk expression. Its value is converted to a string whose contents give the shell command
to be run.

For example, the following produces two files, one unsorted list of BBS names,
and one list sorted in reverse alphabetical order:

Code:
awk '{ 
    print $1 > "names.unsorted" 
    command = "sort -r > names.sorted" 
    print $1 | command 
    }' BBS-list

So, as already stated, it's like:

Code:
zsh-4.3.12[sysadmin]% print -l 3 1 2 | sort
1
2
3

These 2 Users Gave Thanks to radoulov For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to exclude a record from unix file

I want to exclude records from my unix file that have a specific pattern. How can I do this? Thanks. Ryan (1 Reply)
Discussion started by: Ryan2786
1 Replies

2. UNIX for Advanced & Expert Users

Print Full record and substring in that record

I have i got a requirement like below. I have input file which contains following fixed width records. 00000000000088500232007112007111 I need the full record and concatenated with ~ and characters from 1to 5 and concatenated with ~ and charactes from 10 to 15 The out put will be like... (1 Reply)
Discussion started by: ukatru
1 Replies

3. Shell Programming and Scripting

awk - sort, then print the high value for each group

Hi @ all I'm trying to achive to this problem, I've a 2-column composed file as the following: 192.168.1.2 2 192.168.1.3 12 192.168.1.2 4 192.168.1.4 3 cpc1-swan1-2-3-cust123.swan.cable.ntl.com 4 192.168.1.3 5 192.168.1.2 10 192.168.1.4 8... (8 Replies)
Discussion started by: m4rco-
8 Replies

4. Shell Programming and Scripting

awk - print record with both string1 and string2

How do I use awk to find the records in a file that contains two specific strings? I have tried piping and using awk two times, but I don't know how to do it in one action. (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

Print all the fields of record using awk

Hi, i want to generate print statement using awk. i have 20+ and 30+ fields in each line Now its priting only first eight fields print statement as output not all. my record is as shown below filename ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

6. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

7. Shell Programming and Scripting

AWK print initial record and double

I have an initial record 0.018 I would like a script that would for i=0;i<200;i++ print 0.018*1 0.018*2 0.018*3 0.018*4 ... 0.018*200 using newline. (7 Replies)
Discussion started by: chrisjorg
7 Replies

8. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

9. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

10. Shell Programming and Scripting

awk print matching records and occurences of each record

Hi all , I have two files : dblp.xml with dblp records and itu1.txt with faculty members records. I need to find out how many dblp records are related to the faculty members. More specific: I need to find out which names from itu1.txt are a match in dblp. xml file , print them and show how many... (4 Replies)
Discussion started by: iori
4 Replies
SA(8)							      System Manager's Manual							     SA(8)

NAME
sa - summarizes accounting information SYNOPSIS
sa [ -a | --list-all-names ] [ -b | --sort-sys-user-div-calls ] [ -c | --percentages ] [ -d | --sort-avio ] [ -D | --sort-tio ] [ -f | --not-interactive ] [ -i | --dont-read-summary-file ] [ -j | --print-seconds ] [ -k | --sort-cpu-avmem ] [ -K | --sort-ksec ] [ -l | --separate-times ] [ -m | --user-summary ] [ -n | --sort-num-calls ] [ -r | --reverse-sort ] [ -s | --merge ] [ -t | --print-ratio ] [ -u | --print-users ] [ -v num | --threshold num ] [ --sort-real-time ] [ --debug ] [ -V | --version ] [ -h | --help ] [ --other-usracct-file filename ] [ --other-savacct-file filename ] [ [ --other-acct-file ] filename ] DESCRIPTION
sa summarizes information about previously executed commands as recorded in the acct file. In addition, it condenses this data into a summary file named savacct which contains the number of times the command was called and the system resources used. The information can also be summarized on a per-user basis; sa will save this information into a file named usracct. If no arguments are specified, sa will print information about all of the commands in the acct file. If called with a file name as the last argument, sa will use that file instead of the system's default acct file. By default, sa will sort the output by sum of user and system time. If command names have unprintable characters, or are only called once, sa will sort them into a group called `***other'. If more than one sorting option is specified, the list will be sorted by the one specified last on the command line. The output fields are labeled as follows: cpu sum of system and user time in cpu seconds re "real time" in cpu seconds k cpu-time averaged core usage, in 1k units avio average number of I/O operations per execution tio total number of I/O operations k*sec cpu storage integral (kilo-core seconds) u user cpu time in cpu seconds s system time in cpu seconds An asterisk will appear after the name of commands that forked but didn't call exec. GNU sa takes care to implement a number of features not found in other versions. For example, most versions of sa don't pay attention to flags like `--print-seconds' and `--sort-num-calls' when printing out commands when combined with the `--user-summary' or `--print-users' flags. GNU sa pays attention to these flags if they are applicable. Also, MIPS' sa stores the average memory use as a short rather than a double, resulting in some round-off errors. GNU sa uses double the whole way through. OPTIONS
-a, --list-all-names Force sa not to sort those command names with unprintable characters and those used only once into the ***other group. -b, --sort-sys-user-div-calls Sort the output by the sum of user and system time divided by the number of calls. -c, --percentages Print percentages of total time for the command's user, system, and real time values. -d, --sort-avio Sort the output by the average number of disk I/O operations. -D, --sort-tio Print and sort the output by the total number of disk I/O operations. -f, --not-interactive When using the `--threshold' option, assume that all answers to interactive queries will be affirmative. -i, --dont-read-summary-file Don't read the information in the system's default savacct file. -j, --print-seconds Instead of printing total minutes for each category, print seconds per call. -k, --sort-cpu-avmem Sort the output by cpu time average memory usage. -K, --sort-ksec Print and sort the output by the cpu-storage integral. -l, --separate-times Print separate columns for system and user time; usually the two are added together and listed as `cpu'. -m, --user-summary Print the number of processes and number of CPU minutes on a per-user basis. -n, --sort-num-calls Sort the output by the number of calls. This is the default sorting method. -r, --reverse-sort Sort output items in reverse order. -s, --merge Merge the summarized accounting data into the summary files savacct and usracct. -t, --print-ratio For each entry, print the ratio of real time to the sum of system and user times. If the sum of system and user times is too small to report--the sum is zero--`*ignore*' will appear in this field. -u, --print-users For each command in the accounting file, print the userid and command name. After printing all entries, quit. *Note*: this flag supersedes all others. -v num --threshold num Print commands which were executed num times or fewer and await a reply from the terminal. If the response begins with `y', add the command to the `**junk**' group. --separate-forks It really doesn't make any sense to me that the stock version of sa separates statistics for a particular executable depending on whether or not that command forked. Therefore, GNU sa lumps this information together unless this option is specified. --debug Print verbose internal information. -V, --version Print the version number of sa. -h, --help Prints the usage string and default locations of system files to standard output and exits. --sort-real-time Sort the output by the "real time" field. --other-usracct-file filename Write summaries by user ID to filename rather than the system's default usracct file. --other-savacct-file filename Write summaries by command name to filename rather than the system's default SAVACCT file. --other-file filename Read from the file filename instead of the system's default ACCT file. FILES
acct The raw system wide process accounting file. See acct(5) (or pacct(5)) for further details. savacct A summary of system process accounting sorted by command. usracct A summary of system process accounting sorted by user ID. BUGS
There is not yet a wide experience base for comparing the output of GNU sa with versions of sa in many other systems. The problem is that the data files grow big in a short time and therefore require a lot of disk space. AUTHOR
The GNU accounting utilities were written by Noel Cragg <noel@gnu.ai.mit.edu>. The man page was adapted from the accounting texinfo page by Susan Kleinmann <sgk@sgk.tiac.net>. SEE ALSO
acct(5), ac(8) 1997 August 19 SA(8)
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy