How search a list of numbers from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How search a list of numbers from a file
# 1  
Old 09-01-2011
How search a list of numbers from a file

Hi Guys!

I have two input files. I want to search each of the numbers (studentid) on inputfile1 from inputfile2 and print the studentid and section that are listed from inputfile1. See the desired output below.


inputfile1.txt:
Code:
studentid
261054689
266605695
269826642
264966513
267759044


inputfile2.txt:
Code:
studentid,class
269356045,100
264679884,100
266565812,440
261167017,440
274742653,100
261054689,440
268487469,440
266747948,100
261056733,440
269466302,100
269826642,430
264161985,100
264751425,440
267759044,100
267636636,100
268619810,100
269610516,430
261105733,440
264966513,100
267827396,440
266288625,100
266605695,100
266122563,390
266665542,440
267704403,440
268251798,100


Desired Output:
Code:
261054689,440
266605695,100
269826642,430
264966513,100
267759044,100


Thanks in advance.


Br,
pinpe
# 2  
Old 09-01-2011
cut the header of inputfile1, then

Code:
grep -f inputfile1 inputfile2

# 3  
Old 09-02-2011
in case grep -f is not available ..
Code:
$ xargs<file1|sed 's, ,|,g;s,^,egrep \",g;s,$,\" file2,g' | sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

2. Shell Programming and Scripting

Search within file1 numbers from list in file2

Hello to all, I hope somebody could help me with this: I have this File1 (real has 5 million of lines): Number Category --------------- -------------------------------------- 8734060355 3 8734060356 ... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

3. UNIX for Dummies Questions & Answers

How to search & list subdirectories with the given file name

Question: How to search & list subdirectories with the given file name? For example: The directory structure looks like; /Builds/DEV/Build_RL01/DDL/ a_tbl_cre.sql ...... /Builds/DEV/Build_RL01/DML/ a_upd.sql .... .... Requirements: 1. I need to find subdirectory DML which is... (0 Replies)
Discussion started by: Siva SQL
0 Replies

4. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

5. Shell Programming and Scripting

List file's name and search string's Line

Hi all, My need is: To list out all the java / jsp files having System.out.println in my project. I need the output as: /home/me/project/file1.java somejavacode somejavacode System.out.println("something"); somejavacode somejavacode somejavacode /home/me/project/file2.java... (8 Replies)
Discussion started by: linuxadmin
8 Replies

6. Shell Programming and Scripting

Search only numbers in a file

Hello team, Suppose I have a file named that has following content: abc123 1897 msxi12 ------------ ######## ((((( rapjagc ))))))) 34229 xxxxxxxxxxxx @@@536 I need those lines that contain only numbers from this file. means -- it should eliminate alphanumber, special characters... (3 Replies)
Discussion started by: singhabm
3 Replies

7. UNIX for Dummies Questions & Answers

Search String in File List

Hi, I have a list of files which can be identified as abcd*.xml where * represent multiple timestamps for multiple files. I need to do following checks 1. Find number of files (which we get by doing following) FILECOUNT=`ls -ltr /dir/abcd*.xml | wc -l` 2. If check 1 gives '1' as... (2 Replies)
Discussion started by: dsrookie
2 Replies

8. Shell Programming and Scripting

Script to search a large file with a list of terms in another file

Hi- I am trying to search a large file with a number of different search terms that are listed one per line in 3 different files. Most importantly I need to be able to do a case insensitive search. I have tried just using egrep -f but it doesn't seam to be able to handle the -i option when... (3 Replies)
Discussion started by: dougzilla
3 Replies

9. UNIX for Dummies Questions & Answers

how to search and list file with wildcard character

hi, I want to search all files in the current working direcotry and to print in comma (,) seperated output. But I have two patterns to search for. Files will be in ABC20100508.DAT format. Search should happen on the format (ABC????????.DAT) along with date(20100508). I can do a ls... (2 Replies)
Discussion started by: anandapani
2 Replies

10. UNIX for Advanced & Expert Users

Search a list of lines in file into files

I have a file (file1) which is like host1 host2 host3 host4 the list goes on............ Now I want the above lines in files to be compared with files under /opt/new/ File names are as below: Dev Prod QA And suppose host1 from file1 is found under Dev(file under /opt/new)... (2 Replies)
Discussion started by: sriram003
2 Replies
Login or Register to Ask a Question