Sponsored Content
Top Forums Shell Programming and Scripting awk script to perform an action similar to vlookup between two csv files in UNIX Post 302915508 by Prit Siv on Wednesday 3rd of September 2014 01:09:35 PM
Old 09-03-2014
awk script to perform an action similar to vlookup between two csv files in UNIX

Hi,

I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files.

Here are the contents of the two files:

File 1:

Code:
Date,ParentID,Number,Area,Volume,Dimensions
2014-01-01,ABC,247,83430.33,857.84,8110.76
2014-01-01,DEF,295,2904.60,139.33,102.95
2014-01-01,ABC,146,11392.70,5017.07,800.96
2014-01-01,XYZ,465,589.76,2.55,1145.33

File 2:

Code:
ID,DATE__C,Parent__ID
PPPG000000tXZWXIA4,2014-01-01,DEF
TTTG000000tXZWYIA4,2014-01-01,ABC
UUUG000000tXZWbIAO,2014-01-01,XYZ

I am trying to do a lookup between the two files based on the date and the parent ID. If the date AND The parent ID are the same, the "ID" (first column from in file 2) needs to be copied to file 1 (as the first column). If they are not the same, then a blank should be copied to file 1.

For example, the output would be as follows:

File 1:

Code:
ID,Date,ParentID,Number,Area,Volume,Dimensions
TTTG000000tXZWYIA4,2014-01-01,ABC,247,83430.33,857.84,8110.76
PPPG000000tXZWXIA4,2014-01-01,DEF,295,2904.60,139.33,102.95
,2014-02-01,ABC,146,11392.70,5017.07,800.96
UUUG000000tXZWbIAO,2014-01-01,XYZ,465,589.76,2.55,1145.33

Can someone please assist?

Really appreciate any help!

Thank you,
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perform action file name written to the pipe

Hello, I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe. There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file. cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

2. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

3. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

4. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

5. Shell Programming and Scripting

How to access files from different directories and to perform search action in those files?

Hi, I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...). (3 Replies)
Discussion started by: bangarukannan
3 Replies

6. Shell Programming and Scripting

Computing the ratio of similar columns in the two files using awk script

Thanks Bartus11 for your help in the following code to compare the two files "t1" and "t2". awk 'NR==FNR{a=1;next}$2 in a{print $2}' t1 t2 First can anyone explain that what is the purpose of assigning a =1? Second, the current script is printing out the matched columns between the... (4 Replies)
Discussion started by: coder83
4 Replies

7. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

8. Shell Programming and Scripting

Vlookup using awk non similar files

I need to vlookup and check the server not found. Source file 1 server1 server2 server3 server4 server5_root server6_silver server7 server7-test server7-temp Source file 2 server1_bronze (6 Replies)
Discussion started by: ranjancom2000
6 Replies

9. UNIX for Beginners Questions & Answers

How to compare two files in UNIX using similar to vlookup?

Hi, I want to compare same column in two files, if values match then display the column or display "NA". Ex : File 1 : 123 abc xyz pqr File 2: 122 aab fdf pqr fff qqq rrr (1 Reply)
Discussion started by: hkoshekay
1 Replies
TOKENS(1)						       AFS Command Reference							 TOKENS(1)

NAME
tokens, tokens.krb - Displays the issuer's tokens SYNOPSIS
tokens [-help] tokens [-h] tokens.krb [-help] tokens.krb [-h] DESCRIPTION
The tokens command displays all tokens (tickets) cached on the local machine for the issuer. AFS server processes require that their clients present a token as evidence that they have authenticated in the server's local cell. The (mostly obsolete) tokens.krb command is the same as tokens except that it also displays the user's Kerberos v4 ticket cache. OPTIONS
-help Prints the online help for this command. All other valid options are ignored. OUTPUT
The output lists one token for each cell in which the user is authenticated. The output indicates the o User's AFS UID, if it is available for display. o Server for which the token is valid (normally, afs). This includes a cell specification. o Day and time the token expires. The output of the Kerberos version of this command, tokens.krb, also reports the following about the Kerberos ticket-granting ticket: the ticket owner, which Kerberos ticket-granting service that issued the ticket (for example, "krbtgt.ABC.COM"), and ticket's expiration date. The string "--End of list--" appears at the end of the output. If the user is not authenticated in any cell, this line is all that appears. EXAMPLES
The following example shows the output when the issuer is not authenticated in any cell. % tokens Tokens held by the Cache Manager: --End of list-- The following example shows the output when the issuer is authenticated in ABC Corporation cell, where he or she has AFS UID 1000. % tokens Tokens held by the Cache Manager: User's (AFS ID 1000) tokens for afs@abc.com [Expires Jan 2 10:00] --End of list-- The following example shows the output when the issuer is authenticated in the ABC Corporation cell, the State University cell, and the XYZ Company cell. The user has different AFS UIDs in the three cells. Tokens for last cell are expired: % tokens Tokens held by the Cache Manager: User's (AFS ID 1000) tokens for afs@abc.com [Expires Jan 3 10:00] User's (AFS ID 4286) tokens for afs@stateu.edu [Expires Jan 3 1:34] User's (AFS ID 22) tokens for afs@xyz.com [>>Expired<] --End of list-- The following example shows the output when the issuer uses the tokens.krb version of the command after authenticating in the ABC Corporation cell using the klog.krb command. % tokens.krb Tokens held by the Cache Manager: User's (AFS ID 1000) tokens for afs@abc.com [Expires Jan 31 00:09] User smiths tokens for krbtgt.ABC.COM@abc.com [Expires Jan 31 00:09] --End of list-- PRIVILEGE REQUIRED
None SEE ALSO
klog(1), unlog(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 TOKENS(1)
All times are GMT -4. The time now is 05:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy