Sponsored Content
Top Forums UNIX for Advanced & Expert Users Executing if dynamic conditions in awk Post 303044067 by cskumar on Thursday 13th of February 2020 07:37:02 AM
Old 02-13-2020
Code:
CONDITIONS="1=CT,2=US_10,3=CT_US_10"

awk -v CONDITION="${CONDITIONS}" -F, '
BEGIN { 
	c=split(CONDITION, cons, ",");
	for (i=1; i<=c; i++) { 
		split(cons[i], cs, "=");
		field=lookup(cs[1]); 
		gsub("[\"]", "", cs[2]); 
		conditions[field]=cs[2];
		}
} 
function lookup(l,  ar){
  ar[1]="1";ar[2]="4";ar[3]="60";ar[4]="17";ar[5]="4";
  if (l in ar) {
    return ar[l];
  }
}
{
n=0;
for (i in conditions) if ($(i)==conditions[i]) n++;
if (n==c) print $0;
}' Record_${FILEDATE}.dat

This User Gave Thanks to cskumar For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

About awk conditions

Hello, Can you explain why in the first 2 commands the awk does not print anything? Is it looking of a specific format ? Thanks. $ echo 12a3 | awk '($1>=2) {print $1}' # prints nothing $ echo 123a | awk '($1>=2) {print $1}' # prints nothing $ echo a123 | awk '($1>=2) {print $1}' a123... (1 Reply)
Discussion started by: majormark
1 Replies

2. UNIX for Advanced & Expert Users

Dynamic Downloading and executing of ELF files

Dear Group, I want to prepare an ELF file which can be downloaded dynamically to any address in the moemory and executes as a new task/thread/process. 1) for this what are all the compileation, linker options while building the ELF file? 2) which parts of ELF file has to modified while... (1 Reply)
Discussion started by: ravinder.are
1 Replies

3. Shell Programming and Scripting

specifying multiple conditions in AWK

how can i specify more than 1 consition in the following AWK statament?? i.e. if $2 is ABCD and $3 is MNOP and $4 is KLPM similarly for OR #!/bin/ksh awk -F '' ' $2 == "ABCD" { print $2, $3;}' file.xml (2 Replies)
Discussion started by: skyineyes
2 Replies

4. Shell Programming and Scripting

awk with two conditions

Hi Everyone, # cat 1 1;2;3;4;5;6 1;2;3;4;5; # awk -F ";" '$5 == "5"' 1 1;2;3;4;5;6 1;2;3;4;5; but the output is should be just "1;2;3;4;5;6" means 1st condition: $5 is 5; 2nd condition: $6 is not empty, please advice. Thanks (2 Replies)
Discussion started by: jimmy_y
2 Replies

5. Shell Programming and Scripting

Conditions in awk

Hi there, here is my command ssh host.local "/path/to/my/perscript/hostconfig.pl -s $HOST -d |awk '{if (\$4 > 120)print \"My error message\";exit}{s=0; for (i=1; i<=NF; i++) s++; if(s == 13) print \$3}'" The problem is if conditional 1 is met (i.e $4 > 120), i don't see "My error message", the... (5 Replies)
Discussion started by: urello
5 Replies

6. Shell Programming and Scripting

awk with conditions

Hi All, I have a file with below contents. "en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public I want to take the interface name from the file and convert it as ipaddress using ifconfig command get the output like below en6 ->... (2 Replies)
Discussion started by: kamauv234
2 Replies

7. Shell Programming and Scripting

awk three conditions

I'm having a problem pulling UID's from data. The data outputs a user's UID in one of three ways: 1. Error User user_name already assigned with <UID> 2. Success <UID> reserved for user_name 3. <a load of crap because there was a db failure yet somehow the UID is still in there> I typically... (5 Replies)
Discussion started by: MaindotC
5 Replies

8. Shell Programming and Scripting

Shell script executing both the conditions.

I have written this script. This is used for creating a backup folder. #!/bin/sh #set -x . /home/.profile usage="Usage is $0" usage="$usage " # Use the getopt utility to set up the command line flags. set -- `/usr/bin/getopt b: $*` # Process individual command line arguments while ;... (1 Reply)
Discussion started by: arijitsaha
1 Replies

9. Shell Programming and Scripting

If conditions in awk

Hello Friends, I need to find some CDRs in production servers whose 1st field value and 2nd field value = 1 and 11th looks like 45.123... where there are more than 3 digits after comma.so i wrote a one liner, something like below but does not work, however when i used first and second conditions... (8 Replies)
Discussion started by: EAGL€
8 Replies

10. Shell Programming and Scripting

awk problems - awk ignores conditions

awk 'BEGIN{ if('"$CATE"'<'"${WARN}"') printf ("%s", "'"`Kfunc "" ; break`"'") else if (('"${CATE}"'>='"${WARN}"') && ('"${CATE}"'<'"${CRIT}"')) printf ("%s", "'"`Wfunc ""; break`"'") else if ('"${CATE}"'>='"${CRIT}"') printf... (6 Replies)
Discussion started by: SkySmart
6 Replies
RSAUTL(1)							      OpenSSL								 RSAUTL(1)

NAME
rsautl - RSA utility SYNOPSIS
openssl rsautl [-in file] [-out file] [-inkey file] [-pubin] [-certin] [-sign] [-verify] [-encrypt] [-decrypt] [-pkcs] [-ssl] [-raw] [-hexdump] [-asn1parse] DESCRIPTION
The rsautl command can be used to sign, verify, encrypt and decrypt data using the RSA algorithm. COMMAND OPTIONS
-in filename This specifies the input filename to read data from or standard input if this option is not specified. -out filename specifies the output filename to write to or standard output by default. -inkey file the input key file, by default it should be an RSA private key. -pubin the input file is an RSA public key. -certin the input is a certificate containing an RSA public key. -sign sign the input data and output the signed result. This requires and RSA private key. -verify verify the input data and output the recovered data. -encrypt encrypt the input data using an RSA public key. -decrypt decrypt the input data using an RSA private key. -pkcs, -oaep, -ssl, -raw the padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP, special padding used in SSL v2 backwards compatible handshakes, or no padding, respectively. For signatures, only -pkcs and -raw can be used. -hexdump hex dump the output data. -asn1parse asn1parse the output data, this is useful when combined with the -verify option. NOTES
rsautl because it uses the RSA algorithm directly can only be used to sign or verify small pieces of data. EXAMPLES
Sign some data using a private key: openssl rsautl -sign -in file -inkey key.pem -out sig Recover the signed data openssl rsautl -verify -in sig -inkey key.pem Examine the raw signed data: openssl rsautl -verify -in file -inkey key.pem -raw -hexdump 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world The PKCS#1 block formatting is evident from this. If this was done using encrypt and decrypt the block would have been of type 2 (the second byte) and random padding data visible instead of the 0xff bytes. It is possible to analyse the signature of certificates using this utility in conjunction with asn1parse. Consider the self signed example in certs/pca-cert.pem . Running asn1parse as follows yields: openssl asn1parse -in pca-cert.pem 0:d=0 hl=4 l= 742 cons: SEQUENCE 4:d=1 hl=4 l= 591 cons: SEQUENCE 8:d=2 hl=2 l= 3 cons: cont [ 0 ] 10:d=3 hl=2 l= 1 prim: INTEGER :02 13:d=2 hl=2 l= 1 prim: INTEGER :00 16:d=2 hl=2 l= 13 cons: SEQUENCE 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption 29:d=3 hl=2 l= 0 prim: NULL 31:d=2 hl=2 l= 92 cons: SEQUENCE 33:d=3 hl=2 l= 11 cons: SET 35:d=4 hl=2 l= 9 cons: SEQUENCE 37:d=5 hl=2 l= 3 prim: OBJECT :countryName 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU .... 599:d=1 hl=2 l= 13 cons: SEQUENCE 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption 612:d=2 hl=2 l= 0 prim: NULL 614:d=1 hl=3 l= 129 prim: BIT STRING The final BIT STRING contains the actual signature. It can be extracted with: openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614 The certificate public key can be extracted with: openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem The signature can be analysed with: openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin 0:d=0 hl=2 l= 32 cons: SEQUENCE 2:d=1 hl=2 l= 12 cons: SEQUENCE 4:d=2 hl=2 l= 8 prim: OBJECT :md5 14:d=2 hl=2 l= 0 prim: NULL 16:d=1 hl=2 l= 16 prim: OCTET STRING 0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%.. This is the parsed version of an ASN1 DigestInfo structure. It can be seen that the digest used was md5. The actual part of the certificate that was signed can be extracted with: openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4 and its digest computed with: openssl md5 -c tbs MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5 which it can be seen agrees with the recovered value above. SEE ALSO
dgst(1), rsa(1), genrsa(1) 1.0.1e 2013-02-11 RSAUTL(1)
All times are GMT -4. The time now is 03:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy