Sponsored Content
Top Forums Shell Programming and Scripting Match first column and separate entries Post 302786629 by kaav06 on Wednesday 27th of March 2013 11:09:53 PM
Old 03-28-2013
Thanks for reply.

Actually, this one common entry is inserted by me because file was big.

So, it doesn't provide me entries which are already actually present for example my actualt file contain following data

file 1

Code:
17201863
17201862
17201861
17201713
17201710
17201705
17201612
17201610
17201046
17201045
17201028
17200914
17199055
17199053
17199051
17199020
17197650
17197037
17196795
17196758
17196314
17196066
17196055
17196051
17196048
17195919
17195887
17195882
17195735
17195721
17195514
17195402
22466430
22466427
20805927
20126420
19454110
17194333
17194289
17194275
17194268
17192951
17192894
17192893
17192163
17192159
17191267
17191266
17191265
17190849
17190529
17190525
17189651
17189581
17188848
17188847
17188842
17188743
17187491
17187023
17186187
17185511
17185000
17184924
17183827
17183692
17183446
17182104
17181912
17181601
17181600
17181424
17180712
17179916
17178644
17178474
17177985
17176505
17176493
17176206
17175607
17174406
17174336
17174064
17174018
17172255
17171663
17171603
17171602
17170563
17170470
17170166
17167926
17167342
17167340
17167030
17166485
17164645
17164638
17163811
17163803
17162830
17162825
17162656
17162655
17162653
17162652
17162629
17162626
17162623
17162489
17162458
17162450
17161829
17160586
17160504
17159457
17158747

file2

Code:
15489339	172460
15791247	172460
17065234	172460
18425118	172460
21910973	172460
9851916	172461
14704431	172461
16845399	172461
9851916	172462
12520011	172462
12654719	172462
14704431	172462
9851916	172463
19800275	172463
9851916	172464
11167013	172464
12520011	172464
12654719	172464
9851916	172465
9851916	172466
11099033	172466
12520011	172466
12654719	172466
14551910	172466
17417969	172466
17704769	172466
18692475	172466
9851916	172467
12520011	172467
12600937	172467
12654719	172467
15990876	172467
17409073	172467
21437264	172467
22412383	172467
9851916	172468
11099033	172468
12520011	172468
12654719	172468
14551910	172468
14704431	172468
15331665	172468
19526056	172468
9851916	172470
12520011	172470
12654719	172470
2422655	172471
8244003	172471
9851916	172471
12062062	172471
12520011	172471
12654719	172471
14551910	172471
14704431	172471
9851916	172472
12520011	172472
12654719	172472
9851916	172473
10535731	172473
15653635	172473
18245353	172473
9851916	172474
11099033	172474
12520011	172474
12654719	172474
14551910	172474
17090602	172474
17704769	172474
18062952	172474
9851916	172475
12520011	172475
12654719	172475
9851916	172476
14704431	172476
17676955	172476
9851916	172477
12520011	172477
12654719	172477
17158747	172477

expected output is

Code:
17158747	172477

I got this correct result

But when I compared complete file it doesn't retrieve anything I dont know why?
ANd, my files are big that I cant attach here

---------- Post updated at 12:39 PM ---------- Previous update was at 12:05 PM ----------

Hi

Thanks all

I got results now from this code , there was error of tab separation:

Code:
awk '{  gsub(/\r/, "")
        gsub(/ *\t/, "\t")}
FNR == NR {f[$1]
        next}
{       for(n = split($1, f1, ","); n > 0; n--)
                if(f1[n] in f) {
                        $1 = f1[n]
                        print
                }
}' firstfile.txt FS="\t" OFS="\t" second.txt


Last edited by kaav06; 03-27-2013 at 11:41 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

separate out the column

I know "awk -F:" will separate out the column by ":" , now if I what to separate out the column by space also , what can I do ? for example : #ps -ef |grep telnet root 10159 702 0 15:45 ? 00:00:00 in.telnetd: 192.168.0.1 how to separate out the column so that the column as below, ... (6 Replies)
Discussion started by: ust
6 Replies

2. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

3. UNIX for Dummies Questions & Answers

awk to match multiple regex and create separate output files

Howdy Folks, I have a list that looks like this: (file2.txt) AAA BBB CCC DDD and there are 24 of these short words. I am matching these patterns to another file with 755795 lines (file1.txt). I have this code for matching: awk -v f2=file2.txt ' BEGIN { while(... (2 Replies)
Discussion started by: heecha
2 Replies

4. Shell Programming and Scripting

extract DDL - output every match to separate file

Hi, i want to extract the 'CREATE INDEX' or 'CREATE UNIQUE INDEX' statements from a ddl file and output each match to a separate file. i was looking around the net but couldnīt find anything. a possible sed-script could be: sed -n '/CREATE*INDEX*/,/COMMIT/p' filename.ddlbut i couldnīt find out... (11 Replies)
Discussion started by: CactusMoon
11 Replies

5. Shell Programming and Scripting

Match first column entries precisely and fetch whatever in front of it

Hi all I have 2 files: first file AABC TTYP JKBH CVBN NHJK KJHM Second file is AABC,XCYU,JUHD Alllele1 GACXT It is approved study TTYP,JKBH Allele2 PPRD It is clinical trial study JKBH Allele2 PPRD ... (5 Replies)
Discussion started by: Priyanka Chopra
5 Replies

6. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. UNIX for Dummies Questions & Answers

Want to separate one column

I have one command which provide following output related to file system and disk space utilization Filesystem kbytes used avail %used Mounted on /dev/lvol3 131072 73407 54088 58% / /abc/lvol1 59797 30314 2350300 ... (8 Replies)
Discussion started by: Nakul_sh
8 Replies

8. Shell Programming and Scripting

[Solved] Pattern match and write to separate files

I need to parse a file and depending on a patern match(in the insert job line) separate files have to be created with a line added (content in file2). Mapping for pattern match and add line : for Alpha 123 for Beta 234 for Gamma 345 no match (goes into another file) File 1 ... (3 Replies)
Discussion started by: w020637
3 Replies

9. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

10. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies
All times are GMT -4. The time now is 03:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy