Get specific values from a file, help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get specific values from a file, help
# 1  
Old 06-20-2015
Get specific values from a file, help

Dear all,

I have a specific problem that i cannot solve and I hope someone here can help me. Smilie

I have two text files with one column of values.
Example:

File1:
Code:
67        
94                     
95                     
.
.

File2
Code:
0.1
0.003
0.5
.
.

File1 contains the row numbers that value I need from File2. For example the output should be like this:

Theoretical outfile:
Code:
0.4 (row 67 from File2)
0.5 (row 94 from File2)
0.1 (row 95 from File2)
etc...

Is it possible to do this with awk?

I would really appritiate if someone can help me.

Thanks,
Laszlo
Moderator's Comments:
Mod Comment Please use CODE tags for sample input, sample output, and code segments as required by forum rules.

Last edited by Don Cragun; 06-20-2015 at 03:30 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 06-20-2015
Hello Laszlo,

Following may help you in same.
Code:
awk 'FNR==NR{A[NR]=$0;next} ($0 in A){print A[$0]}' file2 file1

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 06-20-2015
Thank you! It works Smilie
# 4  
Old 06-20-2015
Try also
Code:
awk 'FNR==NR {A[$1];next} FNR in A' file1 file2

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a content in a file with specific interval base on the delimited values using UNIX command

Hi All, we have a requirement to split a content in a text file every 5 rows and write in a new file . conditions: if 5th line falls between center of the statement . it should look upto after ";" files are below format: 1 UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS' 2 WHERE... (3 Replies)
Discussion started by: KK230689
3 Replies

2. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

3. Shell Programming and Scripting

Sum values of specific column in multiple files, considering ranges defined in another file

I have a file (let say file B) like this: File B: A1 3 5 A1 7 9 A2 2 5 A3 1 3 The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines... (3 Replies)
Discussion started by: Bastami
3 Replies

4. UNIX for Dummies Questions & Answers

Switching the values in a specific column of a text file

Hi, I have a space de-limited text file. In the fifth column, I would like to switch "1"s with "2"s. How do I go about doing that? Thanks! Sample input: 0 311000259 0 0 1 1 0 311000397 0 0 1 2 0 311000491 0 0 2 1 0 311000516 0 0 2 1 0 311000541 0 0 1 1 0 311000558 0 0 2 1 0 311000566 0... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

6. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

7. Shell Programming and Scripting

[solved] how to get specific env variable values into a file

greetings! how do i get an env variable that looks like this when echoed: into a file that looks like this: keeping in mind that the two constants are the fields from the env variable will always be in odd positions of the string that need to go into the file AND they will always start... (3 Replies)
Discussion started by: crimso
3 Replies

8. Shell Programming and Scripting

Sorting multi-column values from a specific file

Hi, all. I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Discussion started by: canimsin
4 Replies

9. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

10. UNIX for Dummies Questions & Answers

finding specific values in a within a file

Hi everyone, Can anyone guide me on how to search through a huge file and look on specific column and if it finds a discrepancy on that column that does not conform to the specified criteria, ie (1) Numeric and (3) alpha chars F123 or G333..etc, etc! then idientify it and redirect... (3 Replies)
Discussion started by: Gerry405
3 Replies
Login or Register to Ask a Question