Group search (multiple data points) in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Group search (multiple data points) in Linux
# 1  
Old 12-15-2009
Group search (multiple data points) in Linux

Hi All I have a data set like this tab delimited:

Code:
weft fgr-1 345 -1 fgrythdgd
weft fgr-3 456 -2 ghjdklflllff
weft fgr-11 456 -3 ghtjuffl
weft fgr-1 213 -2 ghtyjdkl
weft fgr-34 567 -5 fghytkflf
frgt fgr-36 567 -1 ghrjufjf
frgt fgr-45 678 -2 ghjruir
frgt fgr-34 546 -5 gjjjgkldlld
frgt fgr-3 345 -3 ghjfkkflklfl
frgt fgr-1 567 -3 gjjjgjkgkgklg

I want to perform a group search using the second column, id (fgr-36, fgr-45...) and out put those line in the above file that contains the key.

I can perform for each id. but need to know how to do it using awk or any other scripting language using a group of keys.
For example if I want to search using ids fgr-11, fgr-34 & fgr-1, I need the output as:

Code:
weft fgr-11 456 -3 ghtjuffl
weft fgr-34 567 -5 fghytkflf
frgt fgr-34 546 -5 gjjjgkldlld
frgt fgr-1 567 -3 gjjjgjkgkgklg
weft fgr-1 213 -2 ghtyjdkl

Please let me know the best way to search with multiple key words?

LA
# 2  
Old 12-15-2009
One way is to use grep -f file. Edit a new file to look like this, call it file.grep (name does not matter):
Code:
fgr-11 
fgr-34
fgr-1

Code:
grep -f file.grep  myinputfile >  newoutputfile

# 3  
Old 12-15-2009
Something like this?

Code:
awk '$2=="fgr-11" || $2=="fgr-34" || $2=="fgr-1"' file

# 4  
Old 12-15-2009
Code:
grep -E " fgr-11 | fgr-34 | fgr-1 " urfile

egrep " fgr-11 | fgr-34 | fgr-1 " urfile



---------- Post updated at 08:22 PM ---------- Previous update was at 08:21 PM ----------

Quote:
Originally Posted by jim mcnamara
One way is to use grep -f file. Edit a new file to look like this, call it file.grep (name does not matter):
Code:
fgr-11 
fgr-34
fgr-1

using fgr-11 and fgr-1 will give the wrong answer.
# 5  
Old 12-16-2009
Code:
gawk '$2~/fgr-(11|34|1)/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for Multiple strings in a given date range and print the Group if they exists

Hi, I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format: ------------------------------------------------------------------------------------------------------------------------- ID: FIRST ID MESSAGE: Event Message... (5 Replies)
Discussion started by: linuxuser999
5 Replies

2. Shell Programming and Scripting

Ranking data points from multiple files

I need to rank a large number of data points that exist in multiple files. My data points (Column 3) are based on unique values in columns 1 and 2. I need to rank the values that are in File 1, Column 3. For instance: Input File 1 AAA BBB 10 CCC DDD 16 EEE FFF 20 Input File 2 ... (47 Replies)
Discussion started by: ncwxpanther
47 Replies

3. Shell Programming and Scripting

Linux - Calculations between multiple rows of data

Morning All, I am needing assistance with a calculation process, which performs calculations on a group of records. Here is a breakdown of my requirement: Col1 = Always same value. Col2 = Grouping Column, and will have the same value for 5/6/7 records for example. Col3 = Date Col4 =... (3 Replies)
Discussion started by: RichZR
3 Replies

4. UNIX for Dummies Questions & Answers

Finding data value that contains x% of points

Hi, I need help on finding the value of my data that encompasses certain percentage of my total data points (n). Attached is an example of my data, n=30. What I want to do is for instance is find the minimum threshold that still encompasses 60% (n=18), 70% (n=21) and 80% (n=24). manually to... (4 Replies)
Discussion started by: ida1215
4 Replies

5. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

6. Shell Programming and Scripting

Split, Search and Reformat by Data Group

Hi, I am writing just to share my appreciation for help I have received from this site in the past. In a previous post Split File by Data Group I received a lot of help with a troublesome awk script to reformat some complicated data blocks. What I learned really came in hand recently when I... (1 Reply)
Discussion started by: mkastin
1 Replies

7. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

8. Shell Programming and Scripting

recoding data points using SED??

Hello all, I have a data file that needs some serious work...I have no idea how to implement the changes that are needed! The file is a genotypic file with >64,000 columns representing genetic markers, a header line, and >1100 rows that looks like this: ID 1 2 3 4 ... (7 Replies)
Discussion started by: doobedoo
7 Replies

9. Shell Programming and Scripting

to extarct data points

suppose u have a file which consist of many data points separated by asterisk Question is to extract third part in each line . 0.0002*0.003*-0.93939*0.0202*0.322*0.3332*0.2222*0.22020 0.003*0.3333*0.33322*-0.2220*0.3030*0.2222*0.3331*-0.3030 0.0393*0.3039*-0.03038*0.033*0.4033*0.30384*0.4048... (5 Replies)
Discussion started by: cdfd123
5 Replies

10. Shell Programming and Scripting

Search and replace string between 2 points

I have a file that contains the following string. connect odemgr/bank123@odsd I am liiking to write a scrupt that will change the par of the string between the "/" and the "@" anyhelp qwould be greatly appriciated. (3 Replies)
Discussion started by: whited05
3 Replies
Login or Register to Ask a Question