Taking key values from one file and extracting values from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Taking key values from one file and extracting values from another file
# 1  
Old 01-20-2018
Taking key values from one file and extracting values from another file

Hi,

I have two files with values in both.

File1:
Code:
cat 2 3
dog 4 5
elephant 6 7 
camel 2 3

File2:
Code:
----+--gkf;ajf=
---+----
+----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant |
5 | 7
---++ camel ------ ++++_---- || 8 | 9


I want the final file as:
Code:
cat 4
dog 9
elephant 7
camel 9

The animal values will be taken from file one and used as reference.

File2 is all messed up and the only real separator is |.

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

Last edited by Don Cragun; 01-20-2018 at 09:59 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 01-20-2018
Quote:
Originally Posted by npatwardhan
Hi,

I have two files with values in both.

File1:
Code:
cat 2 3
dog 4 5
elephant 6 7 
camel 2 3

File2:
Code:
----+--gkf;ajf=
---+----
+----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant |
5 | 7
---++ camel ------ ++++_---- || 8 | 9


I want the final file as:
Code:
cat 4
dog 9
elephant 7
camel 9

The animal values will be taken from file one and used as reference.

File2 is all messed up and the only real separator is |.

Thanks.
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, output, and code segments as required by forum rules.
Let's start with the basics:
  1. What have you tried to solve this problem on your own?
  2. What operating system are you using?
  3. What shell are you using?
Then we can move on to the thread specifics:
  1. What is the field separator in File1? I assume it isn't a <space>, or do you disallow animals like mountain lion, Asian elephant, African elephant, eastern diamondback rattlesnake, western diamondback rattlesnake, timber rattlesnake, etc. from your representable data?
  2. How is one supposed to determine what number is to be associated with an animal? If we ignore <newline>s as field and/or record separators, you still have most numbers coming from the text somewhere between the 2nd and 3rd <vertical-bar> character following the field that contains the animal name surrounded by <space>s. Sometimes there are three <vertical-bar>s between the string containing the animal and the string containing the number said should appear in the output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting values after the maximum value in a txt file

Hello, I'm new to scripting and I need to write a bash script. Here is example of file on which I'm working: 0.3092381 0.3262799 0.3425480 0.3578379 0.3719490 0.3846908 0.3958855 0.4053738 0.4130160 0.4186991 0.4223357 0.4238688 ... (14 Replies)
Discussion started by: jeo_fb
14 Replies

2. Shell Programming and Scripting

Fetch the values based on a Key using awk from single file

Hi, Please help to fetch the values for a key from below data format in linux. Sample Input Data Format 11055005|PurchaseCondition|GiftQuantity|1 11055005|PurchaseCondition|MinimumPurchase|400 11055005|GiftCatalogEntryIdentifier|Id|207328014 11429510|PurchaseCondition|GiftQuantity|1... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

3. UNIX for Dummies Questions & Answers

Fixed length file extracting values in columns

How do I extract values in a few columns in a row of a fixed length file? If there are 8 columns and I need to extract values of 2nd,4th and 6 th columns, how do i do that? I used cut command, this I used only for one column. How do I do it more than one column? The below command will give... (1 Reply)
Discussion started by: princetd001
1 Replies

4. Shell Programming and Scripting

Taking sum up all values inside the file

Hi, Taking sum up all values inside the file by using the below command: paste -sd+ filenmae | bc Getting some error like "0705-001: building space exceeded on line1 stdin" The original data looks like SPACE SPACE SPACE 0.123 JOBNAME1 SPACE SPACE 20.325 JOBNAME2 SPACE SPACE... (2 Replies)
Discussion started by: NareshN
2 Replies

5. UNIX for Dummies Questions & Answers

extracting values from file using perl

I would like to read value after $ symbol from a file. For eg a file will be having the following lines. 5,$0,-32768p,32767p,$400014f8,1,, 5,$0,0,0,$400008ce,1,, 5,$0,0,0,$400008d0,1,, i would like to read 400014f8 then 400014f8 and similar all the value after $ symbol.Can any one help... (1 Reply)
Discussion started by: jagadeeshrr
1 Replies

6. Shell Programming and Scripting

extracting values from configuration file

Dear All, i am new to shell scripting, I am working on embedded system based on linux.I am supposed to the read the configuration file and edit another file. presently I would like to read from the configuration file.It would be having values file one below. There is chance of entering... (6 Replies)
Discussion started by: Ratheendran
6 Replies

7. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies

8. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

9. Programming

Extracting Field values for XML file

i have an input file of XML type with data like <nx-charging:additional-parameter name="NX_INTERNATIONALIZED_CLID" value="919427960829"/><nx-charging:finalStatus>RESPONSE , Not/Applicable , OK</nx-charging:finalStatus></nx-charging:process> i want to extract data such that i get the output... (3 Replies)
Discussion started by: junaid.nehvi
3 Replies

10. UNIX for Dummies Questions & Answers

Please help me in taking the values from a file

i have a script, whcih takes values from a file and assign it to one variable. this text value contains name of few object. value contains line by lie. i.e. one after another. when i am assaign the value of this text file to a variable, it accept the value as one liner instead of one by one.... (3 Replies)
Discussion started by: jin
3 Replies
Login or Register to Ask a Question