Modifying/combining two text outputs


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Modifying/combining two text outputs
# 1  
Old 02-05-2019
Modifying/combining two text outputs

greetings,

I have what seems to be a fairly complex task at hand. I am dealing with 3 outputs from a database.

a) Listing of tables. The first 3 characters are always an identifier of an application. See in part b -

Example-

Code:
select tablename from system.tables
ABC1
ABC2
RFV1


b) Each table has a field I need to capture-

Code:
select docname from ABC1
DOCUMENT1
DOCUMENT2
DOCUMENT3

c) The first three characters of that table name, is always the 3 digit identifier of a specific application..

Code:
select identifier, actualname from application
ABC,DataDriven

SO- What I need to do is combine everything into a distinct CSV file, where I have something like this

Code:
(docnameFromABC1),(actualName)
DOCUMENT1, DataDriven
DOCUMENT2, DataDriven

My problem is that I can't join the tables on a certain field. Can anyone think of a fancy way i may be able to use a where clause, or a like clause, or something..or do some fancy awk work on this?
# 2  
Old 02-05-2019
Hi jeffs42885,
You've been with us for well over eight year now. You know we always want to know what operating system and shell you're using, what you have tried to solve this problem on your own, what you have done that is working well, what you have done that isn't getting the output you want, and where you are stuck?

Please give us the above details. Please help us help you.
# 3  
Old 02-05-2019
Quote:
Originally Posted by Don Cragun
Hi jeffs42885,
You've been with us for well over eight year now. You know we always want to know what operating system and shell you're using, what you have tried to solve this problem on your own, what you have done that is working well, what you have done that isn't getting the output you want, and where you are stuck?

Please give us the above details. Please help us help you.
sorry about that. This is AIX/DB2 using KSH.

I have tried various joins on fields that I thought were similar..and other queries.

I did this to get a listing of the application ID's based on the table names-

Code:
select substr(tabname,1,3) from syscat.tables where LENGTH(tabname) = 4 and tabschema='ROOT'

I am stuck here. This is where my skill runs out sadly. I have ideas, just not sure how to implement them, or even how to put them into words!

--- Post updated at 06:27 PM ---

Here's some progress, I think

This output gives me about 90 or so rows, probably more in production that I will need to use below. Snippet-

Code:
db2 => select syscat.tables.tabname from syscat.tables where length(tabname)=4 and tabschema='ROOT'

TABNAME
--------------------------------------------------------------------------------------------------------------------------------
ACA1
AKA1
AZZ1
BHY1
BJA1
....

The column header isn't correct but the results are when I manually did a count from AKA1 and ACA1.

Code:
db2 => select distinct DOCUMENT, 'ACA1' as ID from ACA1 union all select distinct DOCUMENT, 'AKA1' as AKA1 from AKA1

DOCUMENT    ACA1
----------- ----
15FAAA      AKA1
31FAAA      AKA1
31FAAZ      AKA1
2FAAA       ACA1

My next step, is to figure out how to add another column or field to that.

Basically, if column2(AKA1) like "%something" aka (AKA) - add a field next to it. Use an output file to create it. That file looks like this...

Code:
AKA, Program1
ACA, Program2
IED, Program3

So, desired output-

Code:
15FAAA, AKA1, Program1
31FAAA, AKA1, Program1
31FAAZ, AKA1, Program1
2FAAA, ACA1, Program2

I hope I am making somewhat sense Smilie

Last edited by RudiC; 02-06-2019 at 05:05 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing duplicate sequences and modifying a text file

Hi. I've tried several different programs to try and solve this problem, but none of them seem to have done exactly what I want (and I need the file in a very specific format). I have a large file of DNA sequences in a multifasta file like this, with around 15 000 genes: ... (2 Replies)
Discussion started by: 4galaxy7
2 Replies

2. Shell Programming and Scripting

New code for modifying text files in a folder

Hi I want to create a code that can do this for all text files in a folder. The filenames are all listed in the following syntax UNIQUEID-LABID_ - .txt Each file has a unique ID and a different name and the content in the file looks like this: Kinship Analysis Report --- Likelihood... (12 Replies)
Discussion started by: kylle345
12 Replies

3. Shell Programming and Scripting

Small query on modifying the text of file

Hi, I have file with the following text, /analysis2012/533/mc_S10_533/DYJets50/vgtree_1_1_33l.root /analysis2012/533/mc_S10_533/DYJets50/vgtree_2_5_33l.root /analysis2012/533/mc_S10_533/DYJets50/vgtree_6_7_33l.root and many such files. For some operation on these files, I would like... (9 Replies)
Discussion started by: emily
9 Replies

4. Shell Programming and Scripting

Text Formating or Modifying

Hi Experts, I have a text exactly like below in a file: id item_id item_date prin_mkt_val --------------------------- --------------------------- ------------------------------- ------------------------ ... (1 Reply)
Discussion started by: apatil65
1 Replies

5. UNIX for Dummies Questions & Answers

Combining two text files as columns?

I have one space delimited file with multiple columns and one tab delimited file with multiple columns (They have the same number of rows). I want to basically combine these two text files into a new text file by column. How would I go about doing that? (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Searching for a particular string and modifying text within block of data

Hi Forum. Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for. I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the... (5 Replies)
Discussion started by: pchang
5 Replies

7. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

8. Shell Programming and Scripting

Combining two text lines into one

Here is the sample file: 646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset. 647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...) 704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted. I want to combine every non-numbered line... (4 Replies)
Discussion started by: mfavero
4 Replies

9. Shell Programming and Scripting

Inserting text and modifying the file

I am in a dire need of doing this job , please help from shell script or perl script. It will be highly appreciated. Please have a look at the following INPUT file; The first 14 rows are not of interest but I want them to be included in the output file as they are. From the row 14... (3 Replies)
Discussion started by: digipak
3 Replies

10. Shell Programming and Scripting

Help need in modifying the text of .txt file

Hi All, I've written a shell script in which i defined two varibles for example: str=1.0.0.15 timeStamp=2008.03.08 now using this varibles i need to modify a text file. The text content looks like this ************************ * packageNumber : 1.0.0.14 * * date :... (2 Replies)
Discussion started by: vinna
2 Replies
Login or Register to Ask a Question