Sponsored Content
Top Forums Shell Programming and Scripting Sorting within a record using AWK Post 302557899 by radoulov on Thursday 22nd of September 2011 10:27:29 AM
Old 09-22-2011
The code requires the latest awk (awk 4, you can get it here):

Code:
awk 'END {
   print k; for (R in r) print r[R]
  }
/^Module/ {
  if (k) {
  print k; delete r[x]
  for (R in r) print r[R]
  }
  k = $0; delete r; next    
  }
{ 
  r[$NF ~ /NA/ ? 99999999 : $NF, NR] = $0
  }
BEGIN {  
  PROCINFO["sorted_in"] = "@ind_num_asc"
  }' infile

For example:

Code:
zsh-4.3.12[t]% cat infile 
Module :rtlc_BusSelWrap_rtl_copy_121_2_1_12 (rtlc_BusSelWrap_rtl_copy_121_2_1_12)
 M_RTL_MULT_UNS_12_2          1          0         NA
   M_RTL_RSHIFT_2_14          1          0         NA
Module :rtlc_AIMux_rtl_copy_189_4_144_18 (rtlc_AIMux_rtl_copy_189_4_144_18)
         M_RTL_EQ_32          8          8          0
             RTL_AND         28         18    55.5556
       M_RTL_DEC_4_2          2          2          0
             RTL_NOT         13          3    333.333
      M_RTL_PRIM_MUX        152       1044   -85.4406
          M_RTL_EQ_4          2          2          0
         M_RTL_NEQ_4          2          2          0
   M_RTL_RSHIFT_4_32          3          0         NA

Code:
zsh-4.3.12[t]% awk 'END {
   print k
for (R in r) print r[R]
  }
/^Module/ {
  if (k) {
  print k; delete r[x]
  for (R in r) print r[R]
  }
  k = $0; delete r; next
  }
{
  r[$NF ~ /NA/ ? 99999999 : $NF, NR] = $0
  }
BEGIN {
  PROCINFO["sorted_in"] = "@ind_num_asc"
  }' infile 
Module :rtlc_BusSelWrap_rtl_copy_121_2_1_12 (rtlc_BusSelWrap_rtl_copy_121_2_1_12)
 M_RTL_MULT_UNS_12_2          1          0         NA
   M_RTL_RSHIFT_2_14          1          0         NA
Module :rtlc_AIMux_rtl_copy_189_4_144_18 (rtlc_AIMux_rtl_copy_189_4_144_18)
      M_RTL_PRIM_MUX        152       1044   -85.4406
          M_RTL_EQ_4          2          2          0
         M_RTL_NEQ_4          2          2          0
         M_RTL_EQ_32          8          8          0
       M_RTL_DEC_4_2          2          2          0
             RTL_AND         28         18    55.5556
             RTL_NOT         13          3    333.333
   M_RTL_RSHIFT_4_32          3          0         NA

This User Gave Thanks to radoulov For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sorting

Hi, I have used the following code to sort two sets of data: awk '{printf "%10s %s\n",$1,$2}' The first column is text and the second involves numbers. I was just wondering how i would go about sorting the second number so that they ascend from the top? Thanks for any help (4 Replies)
Discussion started by: Jaken
4 Replies

2. Shell Programming and Scripting

sorting in awk

i have following file have following type of data 1~%%~fcashfafh~%%~9797 can i sort(numeric) the file on first field and then on last feild using awk (3 Replies)
Discussion started by: mahabunta
3 Replies

3. Shell Programming and Scripting

AWK, sorting-if and print help.

Little-bit of awk experience, need some of the expert help on here. Browsed around here, got a little further, but I am still missing some pieces. Can you help me fill-in my missing awk cells? Sample data file (leaving out ","'s): Column 1 Column 2 Column 3 Column 4 ... (10 Replies)
Discussion started by: boolean2222
10 Replies

4. Shell Programming and Scripting

Please help in sorting record

dn: uid=peter@exmaple.com,ou=example-com,ou=mail,dc=example,dc=to cn: Peter sn: Norton displayName: Peter Norton dn: uid=ras@exmaple.com,ou=example-com,ou=mail,dc=example,dc=to cn: Ras sn: Kam displayName: Ras Kam i have a text file with 300 entries with multiple ldap entries... (5 Replies)
Discussion started by: learnbash
5 Replies

5. Shell Programming and Scripting

Sorting inside awk

I have an array with five columns and i want to write it to a file. Before writing it i must sort it using the field in the fifth column. _________________________________________ |field 1|field 2|field 3|field 4|field 5| | | | | | | | | | |... (6 Replies)
Discussion started by: beatblaster666
6 Replies

6. Shell Programming and Scripting

Sorting record

Hi all, Can any one help whether we can able to sort a record with delimiter plz ? (3 Replies)
Discussion started by: thelakbe
3 Replies

7. Shell Programming and Scripting

Help with awk sorting with different values

Hello, I have a file as follows: BTA Pos KLD 4 79.7011 5.7711028907 4 79.6231 5.7083918219 5 20.9112 4.5559494707 5 58.0002 3.4423546273 6 38.2569 4.7108176788 6 18.3889 7.3631759258 (1 Reply)
Discussion started by: Homa
1 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

Require original field position after sorting the values in a record

Dear Team, Can any body help me out to get the filed position of the records post sorting using AWK programming. Thanks in advance Example Input: StudentID col-1 col-2 col-3 col-4 1234 14 10 12 13 1235 10 11 12 13 1236 13 12 11 10 ... (3 Replies)
Discussion started by: Srinivasa Reddy
3 Replies

10. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies
DUMP(5) 							File Formats Manual							   DUMP(5)

NAME
dump, ddate - incremental dump format SYNOPSIS
#include <sys/types.h> #include <sys/ino.h> # include <dumprestor.h> DESCRIPTION
Tapes used by dump and restor(1) contain: a header record two groups of bit map records a group of records describing directories a group of records describing files The format of the header record and of the first record of each description as given in the include file <dumprestor.h> is: NTREC is the number of 512 byte records in a physical tape block. MLEN is the number of bits in a bit map word. MSIZ is the number of bit map words. The TS_ entries are used in the c_type field to indicate what sort of header this is. The types and their meanings are as follows: TS_TAPE Tape volume label TS_INODE A file or directory follows. The c_dinode field is a copy of the disk inode and contains bits telling what sort of file this is. TS_BITS A bit map follows. This bit map has a one bit for each inode that was dumped. TS_ADDR A subrecord of a file description. See c_addr below. TS_END End of tape record. TS_CLRI A bit map follows. This bit map contains a zero bit for all inodes that were empty on the file system when dumped. MAGIC All header records have this number in c_magic. CHECKSUM Header records checksum to this value. The fields of the header structure are as follows: c_type The type of the header. c_date The date the dump was taken. c_ddate The date the file system was dumped from. c_volume The current volume number of the dump. c_tapea The current number of this (512-byte) record. c_inumber The number of the inode being dumped if this is of type TS_INODE. c_magic This contains the value MAGIC above, truncated as needed. c_checksum This contains whatever value is needed to make the record sum to CHECKSUM. c_dinode This is a copy of the inode as it appears on the file system; see filsys(5). c_count The count of characters in c_addr. c_addr An array of characters describing the blocks of the dumped file. A character is zero if the block associated with that character was not present on the file system, otherwise the character is non-zero. If the block was not present on the file system, no block was dumped; the block will be restored as a hole in the file. If there is not sufficient space in this record to describe all of the blocks in a file, TS_ADDR records will be scattered through the file, each one picking up where the last left off. Each volume except the last ends with a tapemark (read as an end of file). The last volume ends with a TS_END record and then the tape- mark. The structure idates describes an entry of the file /etc/ddate where dump history is kept. The fields of the structure are: id_name The dumped filesystem is `/dev/id_nam'. id_incno The level number of the dump tape; see dump(1). id_ddate The date of the incremental dump in system format see types(5). FILES
/etc/ddate SEE ALSO
dump(1), dumpdir(1), restor(1), filsys(5), types(5) DUMP(5)
All times are GMT -4. The time now is 08:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy