Match and Append Based on file contexts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match and Append Based on file contexts
# 1  
Old 03-30-2015
Match and Append Based on file contexts

Not Sure how to do this. Some combo of awk and sed perhaps. If String in File1 match String in file2 then append file2

File1.txt
Code:
BullTerrier
Boxer
Bulldog

File2.txt
Code:
<Defined info="AllAnimals" group="Adoptions" setting="animals">

<SomeID ="NumbersRepresentingDogName">
<for>
<add dog="BullTerrier"/>
</for>
</SomeID>

<SomeID ="NumbersRepresentingDogName">
<for>
<each1="adoption" bool="value"/>
<allocate="Boxer" database="databasename"/>
<add dog="Boxer"/>
</for>
</SomeID>

<SomeID ="NumbersRepresentingDogName">
<for>
<add dog="MadDog"/>
</for>
</SomeID>

</DefinedInfo>



AFTER RESULTS
Code:
<Defined info="AllAnimals" group="Adoptions" setting="animals">

<SomeID ="NumbersRepresentingDogName">
<for>
<add dog="--Ok to REMOVE   BullTerrier"/>
</for>
</SomeID>

<SomeID ="NumbersRepresentingDogName">
<for>
<each1="adoption" bool="value"/>
<allocate="Boxer" database="databasename"/>
<add dog="--Ok to REMOVE  Boxer"/>
</for>
</SomeID>

<SomeID ="NumbersRepresentingDogName">
<for>
<add dog="MadDog"/>
</for>
</SomeID>

</DefinedInfo>


Last edited by vgersh99; 03-30-2015 at 12:07 PM.. Reason: code tags, please!
# 2  
Old 03-30-2015
Any attempts from your side?
# 3  
Old 03-30-2015
Moderator's Comments:
Mod Comment This seems to duplicate the discussion in Obtain pattern from file; Append 1st Match.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies

2. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Obtain pattern from file; Append 1st Match

Not clear how to do so. Looking to append the 1st match of said pattern with 'OK TO REMOVE' file containing patter File1.txt RMS_QUANTITY_RT SMS_QUANTITY_RT file to search File2.txt <!-- dec=664, SMS_QUANTITY_RT --> <!-- dec=664, RMS_QUANTITY_RT --> Projected Results <!--... (3 Replies)
Discussion started by: TY718
3 Replies

4. Shell Programming and Scripting

Match value in column and append file with new values

Hi, I need help to match two files based on two columns. file_1 ID AA An Ca Ele Pro Su Ot Tra g13950 No No Yes No Yes Yes Yes Yes g05760 Yes No No No No Yes Yes Yes g12640 No No No No No No No No k17720 No Yes No No No No No Yes g05640 Yes Yes Yes No No Yes Yes Yes file_2 ... (8 Replies)
Discussion started by: redse171
8 Replies

5. 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

6. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

7. Shell Programming and Scripting

Append text from one file to another based on a search from the end of a document

Hi all, I have output files that are all text files with various different extensions. So, if I submit the input file "job_name.inp", when it finishes I get an output file "job_name.dat". A typical input file looks something like this: $CONTRL SCFTYP=RHF RUNTYP=ENERGY MAXIT=199 MULT=1... (4 Replies)
Discussion started by: marcozd
4 Replies

8. Shell Programming and Scripting

Match data based on two fields, and append to a line

I need to write a program to do something like a 'vlookup' in excel. I want to match data from file2 based on two fields (where both match) in file1, and for matching lines, add the data from two of the fields from file2 to file1. If anyone knows something in perl or awk that can do this, I'd be... (20 Replies)
Discussion started by: jamessmith01
20 Replies

9. UNIX for Advanced & Expert Users

cut and append the file based on id

Hi, I have a file which have set of rows and has to create separate files based on the id. Eg: 001_AHaris020 001_ATony030 002_AChris090 002_ASmit060 003_AJhon001 Output: I want three files like 001_A.txt, 002_A.txt and 003_A.txt. 001_A.txt should have ... (1 Reply)
Discussion started by: techmoris
1 Replies

10. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies
Login or Register to Ask a Question