Look up 2 files and print the concatenated output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Look up 2 files and print the concatenated output
# 1  
Old 03-18-2013
Look up 2 files and print the concatenated output

file 1

Sun Mar 17 00:01:33 2013 submit , Name="1234"
Sun Mar 17 00:01:33 2013 submit , Name="1344"
Sun Mar 17 00:01:33 2013 submit , Name="1124"
..
..
..
..
Sun Mar 17 00:01:33 2013 submit , Name="8901"


file 2

Sun Mar 17 00:02:47 2013 1234 execute SUCCEEDED
Sun Mar 17 00:02:48 2013 1344 execute FAILED
Sun Mar 17 00:02:48 2013 1124 execute SUCCEEDED
Sun Mar 17 00:02:49 2013 1222 execute SUCCEEDED
Sun Mar 17 00:02:49 2013 1111 execute SUCCEEDED
Sun Mar 17 00:02:50 2013 1211 execute SUCCEEDED
Sun Mar 17 00:02:50 2013 1111 execute SUCCEEDED
Sun Mar 17 00:02:51 2013 8901 execute FAILED


both the file should be looked up and the out put should be

Sun Mar 17 00:01:33 2013 submit , Name="1234" execute SUCCEEDED
Sun Mar 17 00:01:33 2013 submit , Name="1344" execute FAILED
..
..
..

Any solution please...
# 2  
Old 03-18-2013
This question asked many times and answered too. Based on awk using NR==FNR condition.

Search in the forum , give a try your self and if you are stuck some where pls report.
# 3  
Old 03-18-2013
Got Answer

Code:
awk -F, 'BEGIN{OFS=","}FNR==NR{a[$1$2]=$3;next}($1$2 in a && $3=$3","a[$1$2])'


Last edited by Franklin52; 03-18-2013 at 07:56 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 03-18-2013
Not sure, but your solution did not work for me. The below one is working ok for me.


Code:
$ cat f1
Sun Mar 17 00:01:33 2013 submit , Name="1234"
Sun Mar 17 00:01:33 2013 submit , Name="1344"
Sun Mar 17 00:01:33 2013 submit , Name="1124"

$ cat f2
Sun Mar 17 00:02:47 2013 1234 execute SUCCEEDED
Sun Mar 17 00:02:48 2013 1344 execute FAILED
Sun Mar 17 00:02:48 2013 1124 execute SUCCEEDED
Sun Mar 17 00:02:49 2013 1222 execute SUCCEEDED
Sun Mar 17 00:02:49 2013 1111 execute SUCCEEDED
Sun Mar 17 00:02:50 2013 1211 execute SUCCEEDED
Sun Mar 17 00:02:50 2013 1111 execute SUCCEEDED
Sun Mar 17 00:02:51 2013 8901 execute FAILED


$ awk 'BEGIN { FS="[=\t\" ]+" } NR==FNR{a[$6]=$7" "$8;next} {if($9 in a) {print $0" "a[$9]}}' f2 f1
Sun Mar 17 00:01:33 2013 submit , Name="1234"  execute SUCCEEDED
Sun Mar 17 00:01:33 2013 submit , Name="1344"  execute FAILED
Sun Mar 17 00:01:33 2013 submit , Name="1124"  execute SUCCEEDED

# 5  
Old 03-18-2013
One more query

Tks for the query but one more thing , how can i give input as date in the awk command

suppose i want to awk nawk '/Sun/ && p{print p;p=""}{p=p $0}END{if(p) print p}'

I want to use TZ=IST+24 date +%a instead of giving Sun , how it is possible to give in Awk
# 6  
Old 03-18-2013
Code:
Assign the value to a variable and pass it to awk using "-v"  and then use it inside awk.

# 7  
Old 03-18-2013
Tried failing

nawk -v U="(TZ=IST+24 date +%a)" /U/ && p{print p;p=""}{p=p $0}END{if(p) print p}'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two files and print output

Hi All, i am trying to compare two files in Centos 6. F1: /tmp/d21 NAME="xvda" TYPE="disk" SIZE="40G" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="" NAME="xvda1" TYPE="part" SIZE="500M" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="/boot" NAME="xvda2" TYPE="part"... (2 Replies)
Discussion started by: balu1234
2 Replies

2. Shell Programming and Scripting

Awk: Print Error While Redirecting output in multiple Files

Hi, I have a following code in which I am unable to redirect to multiple files. Can anybody please help with some corrections awk -F, '{ if ( substr($1,26,2)=="02" && substr($1,184,14)=="MTSCC_VALFIRST") { array1++ array2++ array3++ } else if (substr($1,26,2)=="03" &&... (4 Replies)
Discussion started by: siramitsharma
4 Replies

3. Shell Programming and Scripting

Match two columns from two files and print output

Hello, I have two files which are of the following format File 1 which has two columns Protein_ID Substitution NP_997239 T53R NP_060668 V267M NP_058515 P856A NP_001206 T55M NP_006601 D371Y ... (2 Replies)
Discussion started by: nans
2 Replies

4. Shell Programming and Scripting

Comparing 2 xml files and print the differences only in output

Hi....I'm having 2 xml files, one is having some special characters and another is a clean xml file does not have any special characters. Now I need one audit kind of file which will show me only from which line the special characters have been removed and the special characters. Can you please... (1 Reply)
Discussion started by: Krishanu Saha
1 Replies

5. Shell Programming and Scripting

Print only lines where fields concatenated match strings

Hello everyone, Maybe somebody could help me with an awk script. I have this input (field separator is comma ","): 547894982,M|N|J,U|Q|P,98,101,0,1,1 234900027,M|N|J,U|Q|P,98,101,0,1,1 234900023,M|N|J,U|Q|P,98,54,3,1,1 234900028,M|H|J,S|Q|P,98,101,0,1,1 234900030,M|N|J,U|F|P,98,101,0,1,1... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

6. Shell Programming and Scripting

match two key columns in two files and print output (awk)

I have two files... file1 and file2. Where columns 1 and 2 of file1 match columns 1 and 2 of file2 I want to create a new file that is all file1 + columns 3 and 4 of file2 :b: Many thanks if you know how to do this.... :b: file1 31-101 106 0 92 31-101 106 29 ... (2 Replies)
Discussion started by: pelhabuan
2 Replies

7. UNIX for Dummies Questions & Answers

Getting non unique lines from concatenated files

Hi All, Is there a way to get NON unique lines from 2 or more concatenated files? Basically I have several files which are very similar with the exception of few lines and I want to find out which lines are different in each file. Very simple example is file1 contains: 1 2 3 4 5file2... (122 Replies)
Discussion started by: pawannoel
122 Replies

8. Shell Programming and Scripting

compare two files and search keyword and print output

You have two files to compare by searching keyword from one file into another file File A 23 >pp_ANSWER 24 >aa hello 25 >jau head wear 66 >jss oops 872 >aqq olps ploww oww sss 722 >GG_KILLER ..... large files File B Beta done KILLER John Mayor calix meyers ... (5 Replies)
Discussion started by: cdfd123
5 Replies

9. Shell Programming and Scripting

compare columns from seven files and print the output

Hi guys, I need some help to come out with a solution . I have seven such files but I am showing only three for convenience. filea a5 20 a8 16 fileb a3 42 a7 14 filec a5 23 a3 07 The output file shoud contain the data in table form showing first field of... (7 Replies)
Discussion started by: smriti_shridhar
7 Replies

10. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies
Login or Register to Ask a Question