Sponsored Content
Full Discussion: awk program
Top Forums Shell Programming and Scripting awk program Post 302552684 by kjhambrick on Monday 5th of September 2011 06:11:03 AM
Old 09-05-2011
Maybe this:

Code:
#!/bin/sh

gawk '
BEGIN {

   FS = OFS = ","

   NumHead = 3   # Assume:  3-header lines
   NumRead = 0   

   # read the three header lines into a 2-D Array ...

   while ( getline > 0 )
   {
      NumRead ++ 

      for ( i = 1 ; i <= NF ; i ++ )
      {
         HeadAry[ NumRead,i ] = Trim( $i )
      }
      if ( NumRead >= NumHead )
      {
         break
      }
   }
   NumMatch = 0
   delete MatchAry       # GLOBAL
}
function DumpData( NumMatch, NumFld,   i, j, D )
{
   if ( NumMatch == 0 )
   {
      delete MatchAry    # GLOBAL
      return( 0 )
   }

   # Dump the three header lines

   for ( i = 1 ; i <= NumHead ; i ++ )
   {
      D = ""
      printf( "%s%s", D, HeadAry[i,1] )
      D = ","

      for ( j = 2 ; j <= NumFld ; j ++ )
      {
         if ( j in MatchAry )
         {
            printf( "%s%s", D, HeadAry[i,j] )
         }
      }
      print ""
   }

   # Dump the Fields from the Current Data Record

   D = ""
   printf( "%s%s", D, $1 )
   D = ","

   for ( j = 2 ; j <= NumFld ; j ++ )
   {
      if ( j in MatchAry )
      {
         printf( "%s%s", D, MatchAry[ j ])
      }
   }
   print ""

   delete MatchAry       # GLOBAL

   return( 0 )
}
function Trim( InStr )
{
   gsub( /^[\t\n\r ]*/, "", InStr )
   gsub( /[\t\n\r ]*$/, "", InStr )

   return( InStr )
}
# main
{
   # check for qualifying fields, insert indices into MatchAry[]

   for ( i = 2 ; i <= NF ; i ++ )
   {
      if (( N = split( $i, SplitAry, "/" )) == 2 )
      {
         if (( SplitAry[1] +0 > 25 ) && ( SplitAry[2] +0 > 1 ))
         {
            NumMatch ++
            MatchAry[ i ] = $i ""
         }
      }
   }
   NumMatch = DumpData( NumMatch, NF )

}' "$@"

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AWK Program File Help

I have some .dat files that I cannot open and read the data. It is an awk program file, and my question would be to you all is there a way to convert this awk file to ascii text? Thanks (10 Replies)
Discussion started by: ryangfm
10 Replies

2. Shell Programming and Scripting

Error in AWK Program

Hi Friends, I need your help. I am not able to execute one awk program .If you can solve the following small program then i can solve other one. $ vi prg #!/bin/awk -f BEGIN { # Print the squares from 1 to 10 the first way i=1; while (i <= 10) { ... (3 Replies)
Discussion started by: bikas_jena
3 Replies

3. UNIX for Dummies Questions & Answers

AWK program

Hi all, I need to grep the 3 characters from a file, and to fetch the corresponding words to that character. My file is in the following format.. The below text will be in the separate file....say file2.txt ABC This is the first text. DEF This is the second text. GH1 9.8.7890 AB1... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

4. UNIX for Dummies Questions & Answers

AWK Program

:(Hi all, I have a doubt in AWK program. I am writing an awk program which accepts a parameter as input and it should display the corresponding details. if the country as "US" it should be displayed as "United States of America" and the country as "IN" India should be displayed. How can I... (2 Replies)
Discussion started by: sivakumar.rj
2 Replies

5. Shell Programming and Scripting

AWK program

Hi all, I have the following problem and hope someone could help me. I have 184 files, each with 5 columns (c1, c2, c3, c4, c5). I am only interrested in column 5, and would like to paste column 5 from all the 184 files into one file. I have tried the following with two files awk... (20 Replies)
Discussion started by: awkliker
20 Replies

6. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

7. Shell Programming and Scripting

AWK program....

Dear All, facing problem to get data in different fields. SO i am using # to get the data.. please refer my code below... BEGIN { FS=" " } { if ( $1 == "START" ) { i = i+1; SFILENAME = FILENAME } if ( substr($1,2,8) == "filename" ) ... (1 Reply)
Discussion started by: arvindng
1 Replies

8. Shell Programming and Scripting

Help with awk program

i have two files, one looks like this (file1): novelMiR_892 novelMiR_891, novelMiR_852 novelMiR_893 novelMiR_1661 novelMiR_854 novelMiR_1210 novelMiR_1251 novelMiR_855 novelMiR_1252 novelMiR_897 novelMiR_2336,novelMiR_2335,and the second like this... (5 Replies)
Discussion started by: dietmar13
5 Replies

9. Shell Programming and Scripting

awk program in perl

Hi All, I have an AWK code snippet which I want to use in Perl. How can I achieve the same thing in perl? Here I am searching for a pattern in a file and from that matching line, I am extracting the 3rd column value and storing it in a variable which I later on use this value in a if condition. ... (2 Replies)
Discussion started by: sanzee007
2 Replies

10. Shell Programming and Scripting

If else in awk program

Hi All , I have set of input files with one of the fields as below File 1 -Field 1=BUDGET_CURR_FX File 2 -Field 1=BUDGET_MTH_AVGFX File 3 -Field 1=BUDGET_PREV Now i need to include one extra field in the new file as below Output File 1 -Field 1= BUDGET Field2=CURRENT_FX Output File... (2 Replies)
Discussion started by: Hypesslearner
2 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 11:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy