Sponsored Content
Operating Systems Linux Ubuntu Match col 1 of File 1 with col 1 File 2 and create a 3rd file Post 302329993 by sogi on Tuesday 30th of June 2009 02:10:28 AM
Old 06-30-2009
Both files have no headings

input of file 1 (has one 1 column, as shown below):

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364



input of file 2 (this file has 2,498,588 columns with single digit numbers, starting with column 1 as shown below, each column is separated by a space)

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364
.
.
.
.
.
.
.
.
.
.
.
MXY9423 <--- row #1411


desired output file 3 (with only #364 rows with the ids matched between file1 and file2 and 2,498,588 columns)

MXY2344
MXY2455
.
.
.
.
.
.
.
MXY9150 <--- row #364

Thank you for any help!

---------- Post updated at 11:10 PM ---------- Previous update was at 11:03 PM ----------

I just checked the results I obtained with grep -A1 -A1 -f file1.txt file2 > file3

and they are wrong. Instead of getting only 364 rows, I get 367 and some of the ids of file 1 are missing in the output file 3. I want to match the ids from file1 (my "golden" list) in file2 and output that in file 3
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sum(col) finding from a file

Hi I have an file which looks like country address phone amount sweden |address |phone | 10 | Singapo |address |phone | 20 | Italy-N |address |phone | 30 | denmar |address |phone | 40 | Here i need to do the sum(amount), how to do this in shell scripting Thanks Babu (11 Replies)
Discussion started by: ksmbabu
11 Replies

2. Shell Programming and Scripting

sort and split file by 2 cols (1 col after the other)

Dear All, I am a newbie to shell scripting so this one is really over my head. I have a text file with five fields as below: 76576.867188 6232.454102 2.008904 55.000000 3 76576.867188 6232.454102 3.607231 55.000000 4 76576.867188 6232.454102 1.555146 65.000000 3 76576.867188 6232.454102... (19 Replies)
Discussion started by: Ghetz
19 Replies

3. Shell Programming and Scripting

Compare - 1st col of file

Hi, I have two different files, one has two columns and other has only one column. I would like to compare the first column in the first file with the data in the second file and write a third file with the data that is not present is not common to them. First file:... (26 Replies)
Discussion started by: swame_sp
26 Replies

4. Shell Programming and Scripting

Get columns from another file for match in col 2 in 1st file

Hi, My first file has 592155 9 rs16916098 1 592156 19 rs7249604 1 592157 4 rs885156 1 592158 5 rs350067 12nd file has 9 rs16916098 0 113228129 2 4 19 rs7249604 0 58709070 4 2 2 rs17042833 0 113558750 4 2... (2 Replies)
Discussion started by: genehunter
2 Replies

5. Shell Programming and Scripting

how to add new col in a file

Hi, Experts, I have a requirement as following: my source file: a a a b b c c c c I need add one more colume as following: 1 a 2 a 3 a 1 b 2 b 1 c 2 c (4 Replies)
Discussion started by: ken002
4 Replies

6. UNIX for Advanced & Expert Users

Print line based on highest value of col (B) and repetion of values in col (A)

Hello everyone, I am writing a script to process data from the ATP world tour. I have a file which contains: t=540 y=2011 r=1 p=N409 t=540 y=2011 r=2 p=N409 t=540 y=2011 r=3 p=N409 t=540 y=2011 r=4 p=N409 t=520 y=2011 r=1 p=N409 t=520 y=2011 r=2 p=N409 t=520 y=2011 r=3 p=N409 The... (4 Replies)
Discussion started by: imahmoud
4 Replies

7. Shell Programming and Scripting

Printing from col x to end of line, except last col

Hello, I have some tab delimited data and I need to move the last col. I could hard code it, awk '{ print $1,$NF,$2,$3,$4,etc }' infile > outfile but it would be nice to know the syntax to print a range cols. I know in cut you can do, cut -f 1,4-8,11- to print fields 1,... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

8. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

9. Shell Programming and Scripting

Modifying col values based on another col

Hi, Please help with this. I have several excel files (with and .xlsx format) with 10-15 columns each. They all have the same type of data but the columns are not ordered in the same way. Here is a 3 column example. What I want to do add the alphabet from column 2 to column 3, provided... (9 Replies)
Discussion started by: newbie83
9 Replies

10. Shell Programming and Scripting

Replace col 23 - 26 with new value, non delimited file

hello, i have a undelimited file which contains 229 byte records. i want to change column 23 - 26 with a new value and also change the sign of the data in colulmn 30 - 70. i've tried SED for the first change, but nothing happens: sed 's/\(^.\{22\}\).\{4\}\(.*\)/\0603\2/' inputfile heres an... (8 Replies)
Discussion started by: blt123
8 Replies
overlay(3XCURSES)					  X/Open Curses Library Functions					 overlay(3XCURSES)

NAME
overlay, overwrite - copy overlapped windows SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int overlay(const WINDOW *srcwin, WINDOW *dstwin); int overwrite(const WINDOW *srcwin, WINDOW *dstwin); PARAMETERS
srcwin Is a pointer to the source window to be copied. dstwin Is a pointer to the destination window to be overlayed or overwritten. DESCRIPTION
The overwrite() and overlay() functions overlay srcwin on top of destwin. The srcwin and dstwin arguments do not have to be the same size; only text where the two windows overlap is copied. The overwrite() function copies characters as though a sequence of win_wch(3XCURSES) and wadd_wch(3XCURSES) were performed with the desti- nation window's attributes and background attributes cleared. The overlay() function does the same thing, except that, whenever a character to be copied is the background character of the source win- dow, overlay() does not copy the character but merely moves the destination cursor the width of the source background character. If any portion of the overlaying window border is not the first column of a multi-column character, then all the column positions will be replaced with the background character and rendition before the overlay is done. If the default background character is a multi-column character when this occurs, then these functions fail. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. EXAMPLES
Example 1 Implement a pop-up dialog The following example demonstrates the use of overwrite() to implement a pop-up dialog box. #include <curses.h> /* * Pop-up a window on top of curscr. If row and/or col * are -1 then that dimension will be centered within * curscr. Return 0 for success or -1 if malloc() failed. * Pass back the working window and the saved window for the * pop-up. The saved window should not be modified. */ int popup(work, save, nrows, ncols, row, col) WINDOW **work, **save; int nrows, ncols, row, col; { int mr, mc; getmaxyx(curscr, mr, mc); /* Windows are limited to the size of curscr. */ if (mr < nrows) nrows = mr; if (mc < ncols) ncols = mc; /* Center dimensions. */ if (row == -1) row = (mr-nrows)/2; if (col == -1) col = (mc-ncols)/2; /* The window must fit entirely in curscr. */ if (mr < row+nrows) row = 0; if (mc < col+ncols) col = 0; *work = newwin(nrows, ncols, row, col); if (*work == NULL) return (-1); if ((*save = dupwin(*work)) == NULL) { delwin(*work); return (-1); } overwrite(curscr, *save); return(0); } /* * Restore the region covered by a pop-up window. * Delete the working window and the saved window. * This function is the complement to popup(). Return * 0 for success or -1 for an error. */ int popdown(work, save) WINDOW *work, *save; { (void) wnoutrefresh(save); (void) delwin(save); (void) delwin(work); return(0); } /* * Compute the size of a dialog box that would fit around * the string. */ void dialsize(str, nrows, ncols) char *str; int *nrows, *ncols; { int rows, cols, col; for (rows = 1, cols = col = 0; *str != ''; ++str) { if (*str == ' ') { if (cols < col) cols = col; col = 0; ++rows; } else { ++col; } } if (cols < col) cols = col; *nrows = rows; *ncols = cols; } /* * Write a string into a dialog box. */ void dialfill(w, s) WINDOW *w; char *s; { int row; (void) wmove(w, 1, 1); for (row = 1; *s != ''; ++s) { (void) waddch(w, *((unsigned char*) s)); if (*s == ' ') wmove(w, ++row, 1); } box(w, 0, 0); } void dialog(str) char *str; { WINDOW *work, *save; int nrows, ncols, row, col; /* Figure out size of window. */ dialsize(str, &nrows, &ncols); /* Create a centered working window with extra */ /* room for a border. */ (void) popup(&work, &save, nrows+2, ncols+2, -1, -1); /* Write text into the working window. */ dialfill(work, str); /* Pause. Remember that wgetch() will do a wrefresh() */ /* for us. */ (void) wgetch(work); /* Restore curscr and free windows. */ (void) popdown(work, save); /* Redraw curscr to remove window from physical screen. */ (void) doupdate(); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
copywin(3XCURSES), libcurses(3XCURSES), wadd_wch(3XCURSES), win_wch(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 overlay(3XCURSES)
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy