Sponsored Content
Top Forums Shell Programming and Scripting Grabbing lines from one file based on another file Post 302353641 by gisele_l on Tuesday 15th of September 2009 09:13:09 PM
Old 09-15-2009
Grabbing lines from one file based on another file

Hi everyone,

I have a file that contains multiple columns. Basically the identifiers are on column 1. Here is an example:

Code:
target1  6.7  8.4
target2  5.3  2.3
target3  4.3  2.3

My goal is to pull out certain identifiers from column 1 (pull the entire row) and put it into another file. The list of identifiers that I want will be in another file that looks like this

Code:
target1
target2

So ultimately my output will hopefully look like this:

Code:
target1  6.7  8.4
target2  5.3  2.3

These files are very large. I can do selected ones manually by using the unix code grep but this is a little bit more complex.

thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grabbing lines out of a file based on a date

Hello, I'm new to this forum and am not exactly sure where to post this question, so I'll start here. I'm looking for a command or simple script that will read in a large flat file (contains 2005 data) and will output a new file based on a quarter. Within each row, position 87-90 is a julian... (2 Replies)
Discussion started by: bsp18974
2 Replies

2. UNIX for Dummies Questions & Answers

find lines in another file based on contents in a second file

Hello, I have a file with tab delimited columns like: File1 A 2 C R F 4 D Q C 9 A B ...... I want to grep out the lines in a second file, File2, corresponding to each line in File1 Can I do this: while read a b c d do grep '$a\t$b\t$c\t$d' File2 >>... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

3. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

4. UNIX for Dummies Questions & Answers

how to select lines from one file based on another file

Hi, I would like to know how can I select lines of one file based on a common ID column from another file (keeping the order of the second file). Example of file1: ID A B C D 1-30 1 2 3 5-60 4 5 6 1-20 7 8 9 Example of file2: ID chr pos 1-20 1 20 1-30 1 30 5-60 5 60 Desired... (2 Replies)
Discussion started by: fadista
2 Replies

5. Shell Programming and Scripting

Short program to select lines from a file based on a second file

Hello, I use UBUNTU 12.04. I want to write a short program using awk to select some lines in a file based on a second file. My first file has this format with about 400,000 lines and 47 fields: SNP1 1 12.1 SNP2 1 13.2 SNP3 1 45.2 SNP4 1 23.4 My second file has this format: SNP2 SNP3... (1 Reply)
Discussion started by: Homa
1 Replies

6. Shell Programming and Scripting

Bash script to send lines of file to new file based on Regex

I have a file that looks like this: cat includes CORP-CRASHTEST-BU e:\crashplan\ CORP-TEST /usr/openv/java /usr/openv/logs /usr/openv/man CORP-LABS_TEST /usr/openv/java /usr/openv/logs /usr/openv/man What I want to do is make three new files with just those selections. So the three... (4 Replies)
Discussion started by: newbie2010
4 Replies

7. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

8. UNIX for Dummies Questions & Answers

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

9. UNIX for Advanced & Expert Users

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

10. UNIX for Beginners Questions & Answers

Remove lines from File.A based on criteria in File.B

Hello, I have two files of the following form. I would like to remove from File.A where the first three colum matches values in File.B to give the output in File.C File.A 121 54321 PQR CAT 122 765431 ABC DOG 124 98765 ZXY TIGER 125 86432 GEF LION File.B 122 765431 ABC 125 86432 GEF... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies
semids(2)							   System Calls 							 semids(2)

NAME
semids - discover all semaphore identifiers SYNOPSIS
#include <sys/sem.h> int semids(int *buf, uint_t nids, uint_t *pnids); DESCRIPTION
The semids() function copies all active semaphore identifiers from the system into the user-defined buffer specified by buf, provided that the number of such identifiers is not greater than the number of integers the buffer can contain, as specified by nids. If the size of the buffer is insufficient to contain all of the active semaphore identifiers in the system, none are copied. Whether or not the size of the buffer is sufficient to contain all of them, the number of active semaphore identifiers in the system is copied into the unsigned integer pointed to by pnids. If nids is 0 or less than the number of active semaphore identifiers in the system, buf is ignored. RETURN VALUES
Upon successful completion, semids() returns 0. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The semids() function will fail if: EFAULT The buf or pnids argument points to an illegal address. USAGE
The semids() function returns a snapshot of all the active semaphore identifiers in the system. More may be added and some may be removed before they can be used by the caller. EXAMPLES
Example 1: semids() example This is sample C code indicating how to use the semids() function. void examine_semids() { int *ids = NULL; uint_t nids = 0; uint_t n; int i; for (;;) { if (semids(ids, nids, &n) != 0) { perror("semids"); exit(1); } if (n <= nids) /* we got them all */ break; /* we need a bigger buffer */ ids = realloc(ids, (nids = n) * sizeof (int)); } for (i = 0; i < n; i++) process_semid(ids[i]); free(ids); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
ipcrm(1), ipcs(1), intro(2), semctl(2), semget(2), semop(2), attributes(5) SunOS 5.10 8 Mar 2000 semids(2)
All times are GMT -4. The time now is 07:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy