Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Updating specific fields with awk using conditions Post 302323627 by vgersh99 on Monday 8th of June 2009 02:25:01 PM
Old 06-08-2009
Having a 'look up' file gia.cfg:
Code:
PI|Invalid Product
SK|Invalid SKU
QM|Missing Quantity
UD|Unknown Destination

and a file gia.txt to be processed:
Code:
01440|27722011|37271144|PI:SK
03421|908900-APA-2121|90-APAJL-11AAP|QM
43033|21XZ121L|QUMU34121A|QM:PI
45131|10-11-21AJQX|34PAM-42|UD

nawk -f gia.awk gia.cfg gia.txt

gia.awk:
Code:
BEGIN {
  FS=OFS="|"

  SEPlistIN=":"
  SEPlistOUT=","

  STRunknown="Unknown Key"
}
FNR==NR {
  key[$1]=$2
  next
}
{
  str=""
  n=split($NF, a, SEPlistIN)
  for(i=1;i<=n; i++)
    str=( ((i==1)? "":str SEPlistOUT)  ((a[i] in key)? key[a[i]] : STRunknown) )
  $NF=str
  print
}


Last edited by vgersh99; 08-19-2009 at 09:00 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk summing specific lines and fields

Hi I would like to know if it is possible to sum some specific fields. I have this x;x;x;x;x;x;x;x;467,390,611 Bytes;0.435291 GB;0.062247 GB;0.373045 GB;11,225;157 a;a;a;a;a;a;a;a;13,805,156,846 Bytes;12.857054 GB;1.838559 GB;11.018495 GB;151,063;18,933 b;b;b;b;b;b;b;b;232,797,478,723... (5 Replies)
Discussion started by: nakaedu
5 Replies

2. UNIX for Dummies Questions & Answers

Read the file and generate specific fields by awk

Hi I need to generate these output file from the below input file. Output : customer_id as customer, zip as zip_cd, catg_cd as catg, Input: out.customer::in.customer_id; out.zip_cd::in.zip; out.catg::in.catg_cd; Could you please help me on this. Please use code tags next... (1 Reply)
Discussion started by: Murugesh
1 Replies

3. Shell Programming and Scripting

awk partial string match and add specific fields

Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :). file ... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

awk to output match and mismatch with count using specific fields

In the below awk I am trying output to one file those lines that match between $2,$3,$4 of file1 and file2 with the count in (). I am also trying to output those lines that are missing between $2,$3,$4 of file1 and file2 with the count of in () each. Both input files are tab-delimited, but the... (7 Replies)
Discussion started by: cmccabe
7 Replies

5. Shell Programming and Scripting

awk to combine all matching fields in input but only print line with largest value in specific field

In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited, that are in $1 of gene which is just a single column of text. However only the line with the greatest $9 value in input needs to be printed. So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies

6. Shell Programming and Scripting

Getting max value of specific fields with awk

Hello All, Here is am trying to get maximum value of third field depending on first,second and fourth fields with awk command . delimeter is pipe(|) . input 0221|09|14.25|aaa 0221|09|44.27|aaa 0221|09|44.33|aaa 0221|09|44.53|bbb 0221|09|34.32|bbb 0221|09|37.13|bbb... (5 Replies)
Discussion started by: sayami00
5 Replies

7. Shell Programming and Scripting

awk to print fields that match using conditions and a default value for non-matching in two files

Trying to use awk to match the contents of each line in file1 with $5 in file2. Both files are tab-delimited and there may be a space or special character in the name being matched in file2, for example in file1 the name is BRCA1 but in file2 the name is BRCA 1 or in file1 name is BCR but in file2... (6 Replies)
Discussion started by: cmccabe
6 Replies

8. UNIX for Beginners Questions & Answers

Grep or awk a unique and specific word across many fields

Hi there, I have data with similar structure as this: CHR START-SNP END-SNP REF ALT PATIENT1 PATIENT2 PATIENT3 PATIENT4 chr1 69511 69511 A G homo hetero homo hetero chr2 69513 69513 T C . hetero homo hetero chr3 69814 69814 G C . . homo homo chr4 69815 69815 C A hetero . . hetero is... (10 Replies)
Discussion started by: daashti
10 Replies

9. Shell Programming and Scripting

awk to assign points to variables based on conditions and update specific field

I have been reading old posts and trying to come up with a solution for the below: Use a tab-delimited input file to assign point to variables that are used to update a specific field, Rank. I really couldn't find too much in the way of assigning points to variable, but made an attempt at an awk... (4 Replies)
Discussion started by: cmccabe
4 Replies
fcinfo(1M)																fcinfo(1M)

NAME
fcinfo - Fibre Channel HBA Port Command Line Interface SYNOPSIS
fcinfo hba-port [-l] [HBA_port_WWN...] fcinfo remote-port [-ls] [-p HBA_port_WWN] [REMOTE_port_WWN...] fcinfo [-V] fcinfo [-?] fcinfo is a command line interface that collects administrative information on fibre channel host bus adapter (HBA) ports on a host. It also collects data on any fibre channel targets that may be connected to those ports in a Storage Area Network (SAN). SUBCOMMANDS The following subcommands are supported: hba-port Lists information for the HBA port referenced by the specified HBA_port_WWN. If HBA_port_WWN is not specified, all fibre channel HBA ports on the host will be listed. remote-port Lists the remote-port information for those remote ports that are specified. If no REMOTE_port_WWN is specified, all remote ports that are visible through HBA_port_WWN are listed. OPTIONS
The following options are supported: -l, --linkstat Lists the link error statistics information for the port referenced by the specified HBA_port_WWN or REMOTE_port_WWN. -p HBA_port_WWN, --port HBA_port_WWN Retrieve remote port information from the HBA_port_WWN of the local HBA port on the host. The -p option can only be used with the remote-port subcommand and is a mandatory option. -s, --scsi-target Lists the SCSI target information for all remote ports the user has asked for. The -p, --port option must always be specified and must be a valid HBA port on the host. This HBA port will be used as the initiator for which to retrieve the SCSI level target information. Note that this will only function on remote port fibre channel World-Wide Names that support an FC4 type of SCSI. -V, --version Prints the version information. -?, --help Prints the usage information. EXAMPLES
Example 1: Listing all HBA ports The following command lists all fibre channel HBA ports on the host: # fcinfo hba-port HBA Port WWN: 210000e08b074cb5 OS Device Name: /dev/cfg/c1 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: N-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200000e08b074cb5 HBA Port WWN: 210100e08b274cb5 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: N-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200100e08b274cb5 HBA Port WWN: 210000e08b072ab5 OS Device Name: /dev/cfg/c3 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: L-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200000e08b072ab5 HBA Port WWN: 210100e08b272ab5 OS Device Name: /dev/cfg/c4 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: N-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200100e08b272ab5 Example 2: Listing HBA ports and link statistics The following command lists information for the HBA ports and the link statistics for those ports: # fcinfo hba-port -l 210000e08b074cb5 210100e08b274cb5 HBA Port WWN: 210000e08b074cb5 OS Device Name: /dev/cfg/c1 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: N-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200000e08b074cb5 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 HBA Port WWN: 210100e08b274cb5 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3108-xx Type: N-port State: online Supported Speeds: 1Gb 2Gb Current Speed: 2Gb Node WWN: 200100e08b274cb5 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Example 3: Listing all remote ports The following command lists all remote ports that are visible through the given HBA port: # fcinfo remote-port -p 210100e08b274cb5 Remote Port WWN: 50020f230000b4af Active FC4 Types: SCSI SCSI Target: yes Node WWN: 50020f200000b4af Remote Port WWN: 210000e08b07daa6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200000e08b07daa6 Remote Port WWN: 20030003ba27c788 Active FC4 Types: SCSI SCSI Target: yes Node WWN: 10000003ba27c788 Remote Port WWN: 210000e08b096a60 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200000e08b096a60 Example 4: Listing remote ports and link statistics The following command lists information for the remote ports and the link statistics for those ports: # fcinfo remote-port -l -p 210100e08b272ab5 Remote Port WWN: 210100e08b296a60 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200100e08b296a60 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 20030003ba27d56d Active FC4 Types: SCSI SCSI Target: yes Node WWN: 10000003ba27d56d Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 4765165 Loss of Signal Count: 4765165 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210100e08b27f7a6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27f7a6 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 50020f230000b897 Active FC4 Types: SCSI SCSI Target: yes Node WWN: 50020f200000b897 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 7 Loss of Signal Count: 7 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210100e08b27daa6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27daa6 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210000e08b074cb5 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200000e08b074cb5 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210100e08b296060 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b296060 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Example 5: Listing all SCSI targets and link statistics The following command lists all remote ports as well as the link statistics and scsi-target information: # fcinfo remote-port -sl -p 210100e08b272ab5 Remote Port WWN: 210100e08b296a60 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200100e08b296a60 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 20030003ba27d56d Active FC4 Types: SCSI SCSI Target: yes Node WWN: 10000003ba27d56d Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 4765165 Loss of Signal Count: 4765165 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 LUN: 0 Vendor: SUN Product: T4 OS Device Name: /dev/rdsk/c4t20030003BA27D56Dd0s2 LUN: 1 Vendor: SUN Product: T4 OS Device Name: /dev/rdsk/c4t20030003BA27D56Dd1s2 Remote Port WWN: 210100e08b27f7a6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27f7a6 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 50020f230000b897 Active FC4 Types: SCSI SCSI Target: yes Node WWN: 50020f200000b897 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 7 Loss of Signal Count: 7 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 LUN: 0 Vendor: SUN Product: T300 OS Device Name: Unknown LUN: 1 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d1s2 LUN: 2 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d2s2 LUN: 3 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d3s2 LUN: 4 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d4s2 LUN: 5 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d5s2 LUN: 6 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d6s2 LUN: 7 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d7s2 LUN: 8 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d8s2 LUN: 9 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d9s2 LUN: 10 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d10s2 LUN: 11 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d11s2 LUN: 12 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d12s2 LUN: 13 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d13s2 LUN: 14 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d14s2 LUN: 15 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d15s2 Remote Port WWN: 210100e08b27daa6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27daa6 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210000e08b074cb5 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200000e08b074cb5 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Remote Port WWN: 210100e08b296060 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b296060 Link Error Statistics: Link Failure Count: 0 Loss of Sync Count: 0 Loss of Signal Count: 0 Primitive Seq Protocol Error Count: 0 Invalid Tx Word Count: 0 Invalid CRC Count: 0 Example 6: Listing SCSI target information The following command lists all remote ports as well as the scsi-target information: # fcinfo remote-port -s -p 210100e08b272ab5 Remote Port WWN: 210100e08b296a60 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200100e08b296a60 Remote Port WWN: 20030003ba27d56d Active FC4 Types: SCSI SCSI Target: yes Node WWN: 10000003ba27d56d LUN: 0 Vendor: SUN Product: T4 OS Device Name: /dev/rdsk/c4t20030003BA27D56Dd0s2 LUN: 1 Vendor: SUN Product: T4 OS Device Name: /dev/rdsk/c4t20030003BA27D56Dd1s2 Remote Port WWN: 210100e08b27f7a6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27f7a6 Remote Port WWN: 50020f230000b897 Active FC4 Types: SCSI SCSI Target: yes Node WWN: 50020f200000b897 LUN: 0 Vendor: SUN Product: T300 OS Device Name: Unknown LUN: 1 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d1s2 LUN: 2 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d2s2 LUN: 3 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d3s2 LUN: 4 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d4s2 LUN: 5 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d5s2 LUN: 6 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d6s2 LUN: 7 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d7s2 LUN: 8 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d8s2 LUN: 9 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d9s2 LUN: 10 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d10s2 LUN: 11 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d11s2 LUN: 12 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d12s2 LUN: 13 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d13s2 LUN: 14 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d14s2 LUN: 15 Vendor: SUN Product: T300 OS Device Name: /dev/rdsk/c4t50020F230000B897d15s2 Remote Port WWN: 210100e08b27daa6 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b27daa6 Remote Port WWN: 210000e08b074cb5 Active FC4 Types: SCSI,IP SCSI Target: no Node WWN: 200000e08b074cb5 Remote Port WWN: 210100e08b296060 Active FC4 Types: SCSI SCSI Target: no Node WWN: 200100e08b296060 See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNW | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ attributes(5) ERROR MESSAGES
Errors that can occur in addition to the errors normally associated with system administration commands: HBA_port_WWN: not found REMOTE_port_WWN: not found 17 Feb 2005 fcinfo(1M)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy