Dynamically prepare the condition using flat file sdata


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dynamically prepare the condition using flat file sdata
# 1  
Old 01-29-2014
Dynamically prepare the condition using flat file sdata

I have a file in which the data looks like

Code:
A,B

My output should be

Code:
T1.A=T2.A
AND T1.B=T2.B

If my input is
Code:
A,B,C

My output should be
Code:
T1.A=T2.A
AND T1.B=T2.B
AND T1.C=T2.C

Currently I am automating my databae script and strucked with this part.Not able to search the exact requirement for this.

I think it can be doen using arrays and I am trying to do that.

Can anyone give me hints or approach?

Last edited by Don Cragun; 01-29-2014 at 04:17 AM.. Reason: Add required CODE tags.
# 2  
Old 01-29-2014
Code:
$ echo "A,B,C" | awk -v RS="," -v ORS="\nAND " ' { print "T1."$1"=T2."$1 } '
T1.A=T2.A
AND T1.B=T2.B
AND T1.C=T2.C

Code:
$ echo "A,B,C" | sed "s/\([^,]*\)/T1.\1=T2.\1/g;s/,/\\
> AND /g"
T1.A=T2.A
AND T1.B=T2.B
AND T1.C=T2.C

# 3  
Old 01-29-2014
Thank you very much.It helped a lot.How can i store the output into a variable?

---------- Post updated at 01:56 PM ---------- Previous update was at 01:50 PM ----------

Yeh.I got it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prepare file run report

I have a requirement to prepare a report. We validate some incoming data fields and create validation_error reports which will contain records which do not pass validation. Once files are processed they will all be dropped under one folder. EMPLOYEE_20140915.txt... (8 Replies)
Discussion started by: member2014
8 Replies

2. Shell Programming and Scripting

Getting data from a flat file based on condition

Hi, I have a flaty file from which i am fetching few columns in tablular form as below code. Now i want to fetch the column 6 and 7 in below code only if it either of them is non zero.However below startement awk -F, '$6==0 && $7==0{exit 1}' ${IFILE} is not working..Not sure where is the... (36 Replies)
Discussion started by: Vivekit82
36 Replies

3. Shell Programming and Scripting

Split file Dynamically

Hello , I have a flat file ( comma separated ) and want to split dynamically . If I provide input 3 then rows 1,4,7 will o/p to a file and rows 2,5,8 will redirect to 2nd file and 3,6,9 rows will go to 3rd file So 3 files will be generated . Could it be possible in Unix? (2 Replies)
Discussion started by: Pratik4891
2 Replies

4. Shell Programming and Scripting

Dynamically creating file names from portions of another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to get... (2 Replies)
Discussion started by: jclanc8
2 Replies

5. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

6. UNIX for Dummies Questions & Answers

Read a file dynamically

Hi my requriment is read the file name dynamically my code is #!/bin/sh file="/c/work/loan/" Header_Trailer_move() { sed '1d;$d' $file| cat >sam.txt } Header_Trailer_move in above given path my list of files or there i have to read file dyanamically when i entered particular file name... (2 Replies)
Discussion started by: sgoud
2 Replies

7. Shell Programming and Scripting

Need to dynamically create a file

I'm trying to write a script that generates a file of varying size filled with random text and am having some difficulties. The major problems are that I'm limited to csh and a lot of the systems I have to run this on don't have a /dev/random (so a wrapper around the dd if=/dev/random or dd... (14 Replies)
Discussion started by: stareja
14 Replies

8. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

9. Shell Programming and Scripting

How can i prepare a file by comparing two other files?

File 1 data: TestA TestB TestC File 2 data: TestA TestD TestE My Output File (pick all from both and create a file without duplicate data) ---------------------------------------------------------------------- TestA TestB TestC (3 Replies)
Discussion started by: manmohanpv
3 Replies

10. Shell Programming and Scripting

dynamically linked file

Hi friends , how do i view a dynamically linked file in unix ? its there on other system and do i have to ftp it in ASCII format or binary ? and after the ftp how do i view it ? thanks in advance veeras (1 Reply)
Discussion started by: sveera
1 Replies
Login or Register to Ask a Question