Sponsored Content
Full Discussion: awk runs but output is empty
Top Forums Shell Programming and Scripting awk runs but output is empty Post 302962852 by cmccabe on Saturday 19th of December 2015 12:27:35 PM
Old 12-19-2015
The resulting output is 0 bytes, so I tried another awk which does produce output, but not in the desired way and I need some help with the output. Thank you Smilie.

Code:
BEGIN { 
    slen = 0; 
} 
 
# get input file(s) 
ARGIND > 1 { 
    ###printf("input_push: DEBUG %s\n",$0); 
    input[$0]; 
    next; 
} 
 
# get single search list 
{ 
    ###printf("search_push: DEBUG %s\n",$0); 
    search[slen++] = $0; 
    next; 
} 
 
END { 
    # sum up data 
    for (sidx = 0;  sidx < slen;  ++sidx) { 
        sval = search[sidx]; 
        ###printf("search_end: DEBUG %s\n",sval); 
 
        split(sval,sary) 
        split(sary[5],a,"-"); 
        ###printf("search_end: DEBUG sary[5]='%s' a[1]='%s'\n",sary[5],a[1]); 
 
        if (a[1] in input) { 
            key = sary[4] OFS sary[5] 
            n[key]++ 
            sum[key] = sary[7] 
        } 
    } 
 
    for (key in n) 
        printf "%s %.1f\n", key, sum[key]/n[key] 
}

then I invoke it awk -f script.awk search.txt input.txt > output.txt

output.txt is close:
chr1:955543 AGRN-6|gc=75 0.7 and $3 should be 1.3 but I can't seem to find the error

---------- Post updated at 11:27 AM ---------- Previous update was at 09:26 AM ----------

I modified the awk to:

Code:
awk '
 NR == FNR {input[$0]; next}
 {
    split($5, a, "-")
    if (a[1] in input) {
         key = $4 OFS $5
         n[key]++
         sum[key] += $7
     }
 }
 END {
     for (key in n) 
         printf "%s %.1f\n", key, sum[key]/n[key]
 }
' input.txt search.txt > output.txt

output.txt
Code:
chr1:955543 AGRN-6|gc=75 1.3

(closer to the desired). Thank you Smilie

Last edited by cmccabe; 12-19-2015 at 01:28 PM.. Reason: added details
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

The output file is empty. Please Help

Dear all, Currently I writing a ksh script to perform some sql query. I already pipe results in a output file. But when I checked it, the output file is empty. Below is part of the script that I wrote: ------------------------------------------------------------------------ function... (4 Replies)
Discussion started by: balzzz
4 Replies

2. Shell Programming and Scripting

command runs, no output

I have a script that searches for specific information from log files. #!/bin/sh sed -n '/*C/,/END/p' /sn/log/OMlog* > crit.out sed -n '/REPT INITIALIZATION/,/err:/p' /sn/log/OMlog* > switchcc.out ./start.awk /sn/log/OMlog* > ARs.out ./end.awk /sn/log/OMlog* > ARe.out cat crit.out... (1 Reply)
Discussion started by: grinds
1 Replies

3. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

4. Shell Programming and Scripting

Output only non-empty arguments

Hello, I am VERY new to shell scripting here, so please go easy. I have an assignment that requires creating a script using bash shell, outputting all command line arguments that are not empty ones such as " ", and showing total number of arguments. I know how to show the total with $# and all... (6 Replies)
Discussion started by: moderwarfare
6 Replies

5. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

6. Shell Programming and Scripting

Script which telnets to a device, runs commands and prints output to a file

I am connecting to a device using telnet, I want my script to perform certain commands : ie- show device , show inventory..etc and write the output it sees from the terminal to a file. this is what I have got : #!/usr/bin/expect -- set running 1 spawn telnet <ip address> expect ... (1 Reply)
Discussion started by: samantha123
1 Replies

7. Shell Programming and Scripting

This function (decode64) runs on gawk but not on busybox awk

Hello, I'm trying to figure out a way to use a decode64 function in an embedded system who has few utilities, including busybox. Right now have something like this (taken from "google base64-and-base85-encoding-awk-scripts" sorry, I'm not able to post urls yet) _decode64() { &&... (4 Replies)
Discussion started by: chilicuil
4 Replies

8. Shell Programming and Scripting

awk runs and produces output but with error

When I run the awk below, I get an error message awk -v OFS='\t' '$(NF-1)=="Benign" || ($(NF-2) OFS $(NF-1))=="Likely Benign" {$(NF)=$(NF-2) OFS $(NF-1)} {print $0 }' input awk: cmd. line:1: (FILENAME=VUS FNR=8) fatal: attempt to access field -1 input Chr Start End Ref ... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. 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
PAPERKEY(1)						      General Commands Manual						       PAPERKEY(1)

NAME
paperkey - extract secret information out of OpenPGP secret keys SYNOPSIS
paperkey [--secret-key=FILE] [--output=FILE] [--output-type=base16|raw] [--output-width=WIDTH] paperkey --pubring=FILE [--secrets=FILE] [--input-type=auto|base16|raw] [--output=FILE] [--ignore-crc-error] [--comment=STRING] [--file-format] paperkey --version MOTIVATION
As with all data, secret keys should be backed up. In fact, secret keys should be backed up even better than other data, because they are impossible to recreate should they ever be lost. All files encrypted to lost keys are forever (or at least for a long time) undecipher- able. In addition to keeping backups of secret key information on digital media such as USB-sticks or CDs it is reasonable to keep an if- all-else-fails copy on plain old paper, for use should your digital media ever become unreadable for whatever reason. Stored properly, paper is able to keep information for several decades or longer. With GnuPG, PGP, or other OpenPGP implementations the secret key usually contains a lot more than just the secret numbers that are impor- tant. They also hold all the public values of key pairs, user ids, expiration times and more. In order to minimize the information that has to be entered manually or with the help of OCR software, paperkey extracts just the secret information out of OpenPGP secret keys. For recovering a secret key it is assumed that the public key is still available, for instance from public internet keyservers. DESCRIPTION
paperkey has two modes of operation: The first mode creates "paperkeys" by extracting just the secret information from a secret key, formatting the data in a way suitable for printing or in a raw mode for further processing. The other mode rebuilds secret keys from such a paperkey and a copy of the public key, also verifying the checksums embedded in the paperkey. This mode is selected when the --pubring option is used, which is required in that case. If a passphrase was set on the origi- nal secret key, the same passphrase is set on the rebuilt key. Input is read from standard-in except when the --secret-key or --secrets option is used; output is printed to standard-out, unless changed with the --output option. SECURITY CONSIDERATIONS
Please note that paperkey does not change the protection and encryption status of and security requirements for storing your secret key. If the secret key was protected by a passphrase so is the paperkey. If the secret key was unprotected the paperkey will not be protected either. OPTIONS
--help, -h Display a short help message and exit successfully. --version, -V Print version information and copyright information and exit successfully. --verbose, -v Print status and progress information to standard-error while processing the input. Repeat for even more output. --output=FILE, -o Redirect output to the file given instead of printing to standard-output. --comment=STRING Include the specified comment in the base16 output. --file-format Paperkey automatically includes the file format it uses as comments at the top of the base16 output. This command simply prints out the file format and exits successfully. OPTIONS FOR EXTRACTING SECRET INFORMATION
--output-type=base16, --output-type=raw Select the output type. The base16 style encodes the information in the style of a classic hex-dump, including line numbers and per-line CRC checksums to facilitate localizing errors in the input file during the recovery phase. The raw, or binary, mode is just a raw dump of the secret information, intended for feeding to barcode generators or the like. --output-width=WIDTH Choose line width in the base16 output mode. The default is 78 characters. --secret-key=FILE File to read the secret key from. If this option is not given paperkey reads from standard-input. OPTIONS FOR RE-CREATING PRIVATE KEYS --input-type=auto, --input-type=base16, --input-type=raw Specify that the given input is either in base16 format, as produced by paperkey, or in raw format. The default, auto, tries to automatically detect the format in use. --pubring=FILE File to read public key information from. It is assumed that the user can get the public key from sources like public internet key- servers. --secrets=FILE File to read the extracted secrets, the paperkey, from. If this is not given then the information is read from standard-input. --ignore-crc-error Do not reject corrupt input and continue despite any CRC errors. EXAMPLES
Take the secret key in key.gpg and generate a text file to-be-printed.txt that contains the secret data: $ paperkey --secret-key my-secret-key.gpg --output to-be-printed.txt Take the secret key data in my-key-text-file.txt and combine it with my-public-key.gpg to reconstruct my-secret-key.gpg: $ paperkey --pubring my-public-key.gpg --secrets my-key-text-file.txt --output my-secret-key.gpg If --output is not specified, the output goes to stdout. If --secret-key is not specified, the data is read from stdin so you can do things like: $ gpg --export-secret-key my-key | paperkey | lpr SEE ALSO
gpg(1), http://www.jabberwocky.com/software/paperkey/ AUTHORS
paperkey is written by David Shaw <dshaw@jabberwocky.com>. PAPERKEY
January 2008 PAPERKEY(1)
All times are GMT -4. The time now is 02:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy