extracting columns from 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting columns from 2 files
# 1  
Old 06-11-2010
extracting columns from 2 files

Hello,

I have 2 files file1 & file2

[File1 content] =
a1 b1
a2 b2
a3 b3
...

[File2 content] =
c1 d1
c2 d2
c3 d3
...

I need to compare if b(i)=c(j) . i,j=1,2,3,4,...

If yes, right a(i) d(j) in output file3 per line

Thankx to help
# 2  
Old 06-11-2010
Try,
Code:
$ paste -d' ' file1 file2 | awk '$2 == $3{ print $1, $4 }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining files using awk not extracting all columns from File 2

Hello All I'm joining two files using Awk by Left outer join on the file 1 File 1 1 AA 2 BB 3 CC 4 DD File 2 1 IND 100 200 300 2 AUS 400 500 600 5 USA 700 800 900 (18 Replies)
Discussion started by: venkat_reddy
18 Replies

2. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

3. Shell Programming and Scripting

extracting columns falling within specific ranges for multiple files

Hi, I need to create weekly files from daily records stored in individual monthly filenames from 1999-2010. my sample file structure is like the ones below: daily record stored per month: 199901.xyz, 199902.xyz, 199903.xyz, 199904.xyz ...199912.xyz records inside 199901.xyz (original data... (4 Replies)
Discussion started by: ida1215
4 Replies

4. Shell Programming and Scripting

Using columns from 2 files and extracting string

Hi All, I have 2 files with a common column. File 1 looks like NAME START POS1 POS2 N1 1234 1236 1237 N2 1245 1248 1250 .. .. File 2 looks like NAME STRING N1 ABCDEFGH N2 EFGHBCD N3 PQRSSTUV .. ...... ... (25 Replies)
Discussion started by: alpesh
25 Replies

5. Shell Programming and Scripting

Extracting columns from multiple files with awk

hi everyone! I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is: awk 'NR==FNR{a=$2; next} {print a, $2}' file1 file2 I added the file3, file4 and... (10 Replies)
Discussion started by: orcaja
10 Replies

6. UNIX for Dummies Questions & Answers

Extracting columns from multiple files with awk

hi everyone! I already posted it in scripts, I'm sorry, it's doubled I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is: awk 'NR==FNR{a=$2; next}... (1 Reply)
Discussion started by: orcaja
1 Replies

7. Shell Programming and Scripting

Extracting only a few columns!!!?

Hi All, I have a text file which looks like below. ################################################ Name:xxxxxxx Version:1.0 Class: 2 City : Bangalore Component Part Action Nb New Part Naming Part Name 12345 default 12345.12345 Bad 23456 ... (6 Replies)
Discussion started by: smarty86
6 Replies

8. Shell Programming and Scripting

Extracting columns

The output of the below command is : # yum -e0 -d0 check-update dnsmasq.i386 2.45-1.1.el5_3 updates ecryptfs-utils.i386 75-5.el5 updates fetchmail.i386 6.3.6-1.1.el5_3.1 updates... (16 Replies)
Discussion started by: proactiveaditya
16 Replies

9. Shell Programming and Scripting

Need help in extracting columns

Hi , I have a file having around 8 columns spereated by space . Now that I need to extract columns from this. The problem is this functionality is needed in a script and the required columns are dynamic and can range from 2 columns to 8 columns at a time . What I tried without luck is ... (6 Replies)
Discussion started by: praveenbvarrier
6 Replies

10. UNIX for Dummies Questions & Answers

Extracting columns from different files for later merging

Hello! I wan't to extract columns from two files and later combine them for plotting with gnuplot. If the files file1 and file2 look like: fiile1: a, 0.62,x b, 0.61,x file2: a, 0.43,x b, 0,49,x The desired output is a 0.62 0.62 b 0.61 0.49 Thank you in advance! (2 Replies)
Discussion started by: kingkong
2 Replies
Login or Register to Ask a Question