Two Huge Texts and Combine Result to Third


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Two Huge Texts and Combine Result to Third
# 1  
Old 09-21-2010
Data Two Huge Texts and Combine Result to Third

hi, i want to examine two file and write some codes to a third file. note that seperators are TAB, not space.

first file:
Code:
 
192.168.1.1  3
192.168.1.2  2
192.168.3.2  2
192.168.7.3  1
...


second file:
Code:
192.168.1.1  1  10.15.1.1  3  30  10.15.2.1  2  40
192.168.1.1  2  10.23.4.5  1  45
192.168.1.1  3  10.15.2.2  2  40  10.15.3.3  1  10
192.168.1.2  1  10.18.3.1  2  50
192.168.1.2  2  10.16.3.2  1  60  10.11.3.9  1  20  10.19.2.1  1  80
192.168.1.2  3  10.23.4.5  1  45
192.168.1.3  1  10.23.6.5  1  45  10.23.5.6  3  30
192.168.1.3  2  10.16.8.2  1  60  10.11.3.9  1  20  10.19.2.1  1  80
192.168.1.3  3  10.15.5.1  2  40  10.15.3.3  1  10
...
192.168.3.2  1  ......
192.168.3.2  2  10.16.9.9  3  20
192.168.3.2  3  ......
...
192.168.7.3  1  10.29.7.9  2  90  10.33.2.7  3  40  10.19.7.7  2  60
192.168.7.3  2  ......
192.168.7.3  3  ......
...

second file is like a database and lists all IPs and their ports (1,2,3) and other data in each line.

i want to get each line from second file where IP and ports are given in first file. and write output to third file as result.

for example, according to data in first file, i want to write to third file:
Code:
10.15.2.2  2  40  10.15.3.3  1  10
10.16.3.2  1  60  10.11.3.9  1  20  10.19.2.1  1  80
10.16.9.9  3  20
10.29.7.9  2  90  10.33.2.7  3  40  10.19.7.7  2  60
...

how can i do it? grep/awk/for/etc..?? SmilieSmilieSmilieSmilie
# 2  
Old 09-21-2010
Try this:
Code:
awk 'NR==FNR{a[$1$2]++;next}
a[$1$2]{
  $1=$2=""
  gsub("^[\t]*","")
  print
}' OFS="\t" firstfile secondfile

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 09-21-2010
Code:
awk 'NR==FNR{a[$1 FS $2]++;next} a[$1 FS $2] {$1=$2="";print}' file1 file2

Looks same. Smilie
This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 09-22-2010
but how can i point third file? on your replies, there is nothing to say: "print to file3"? Smilie

---------- Post updated at 09:35 ---------- Previous update was at 09:30 ----------

yep!! it's done Smilie

Code:
awk 'NR==FNR{a[$1 FS $2]++;next} a[$1 FS $2] {$1=$2="";print}' file1 file2 > file3

thanks for your assist Smilie)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aligning Texts

is there any way to align my text so every column begins on the same line as the previous line? here's my command: printf "THEN ( ${SEARCHPATTB} = Hour = ${CALTOTB} ) %8s => %8s NOW ( ${SEARCHPATT} = Hour = ${CALTOT} ) %7s => %7s Reduced By: %7s -${RESULT}"\\n output i'm currently getting... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Can there be alt-texts to icons?

Can you add hover texts (alt-texts) to icons? It is not always obvious what each of them mean just by looking at them. Sometimes it is clear from the url it points to, but for accessibility reasons alone it would be good to have alt-texts as a standard. (1 Reply)
Discussion started by: figaro
1 Replies

4. Shell Programming and Scripting

How to combine two variable result?

Hi, i have two variables i.e lck_ckm_customer=ckm_customer and(present in some script A) table=ckm_customer(present in script B) in script B i am executing this part if ; then --- ---- ---- fi Now, while comparing in my log file i am getting this result if but i... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

5. UNIX for Dummies Questions & Answers

Texts between 2 strings

Hi, I have a file with texts shown below, <2013 abc <2013 start request pdu dot1q end pdu response pdu dot1q end pdu am searching for the text "dot1q" , when it matches in the file , i need the contents between "<2013 start" and "end pdu". Can some one help on this ? ... (5 Replies)
Discussion started by: giri_luck
5 Replies

6. Shell Programming and Scripting

How to combine 2 texts file and create another file from it?

Hi all, I've the following hostnames & ip addresses saved in host_ip.txt Based on this list, I need to create the following script. where by HH is a hostname and XXXX is an ip address So the final output would be something like this. Currently, I'm doing it manually, replace, copy... (3 Replies)
Discussion started by: type8code0
3 Replies

7. Shell Programming and Scripting

How to concatenate texts in perl only?

Hi, I want to concatenate the texts in the file but there are different scenario's. Ist Scenario. The contents of file has id`language,sequence number,text,language Here id`language is a key pair to identify the correct language. Sequnce number is the order the text being inserted. Text... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

extract texts using awk

Hello, I have two files: File1: a b c d File2: b c e I need 'e' as output.... Thanks.. ---------- Post updated at 12:16 PM ---------- Previous update was at 12:15 PM ---------- (1 Reply)
Discussion started by: shekhar2010us
1 Replies

9. Shell Programming and Scripting

Combine common line from 2 Huge files

Hi, I am having 2 huge files having line count more than 10million. The files look like: File 1 45905099 2059 942961505 3007 8450875165 7007 615565331 3015 9415586035 9012 9871573 5367 4415655 4011 44415539519 5361 3250659295 4001 5950718618 9367 File 2 44415539519 TQ03... (2 Replies)
Discussion started by: rochitsharma
2 Replies

10. Shell Programming and Scripting

Separate sentences from two texts, combine them

I havet two books, one in Swedish, the other in English. Two text files. I want to combine them into one, with each sentence having it's translation next to it. ------------ Text file one. Example sentence in English. Example 2 sentence 2 in English 2. -------------- Text file two. ... (2 Replies)
Discussion started by: LaraMej
2 Replies
Login or Register to Ask a Question