different files for different values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting different files for different values
# 22  
Old 01-14-2009
After using this sed 's spool /SYSTEM/custom/modules/testing/THS_PROF.txt--g'

no getting the correct files also :-)

If only 1 file gets created instead of creating 1 file each for an a/c no i think will solve the problem of so many unwanted files getting created.

So for that i wanted to know that, how can i modify below mentioned sed stmt to create just 1 file for all the account nos with the value passed as argument should be in the file name in place of account no like THS_PROF_G03_20090114155816.txt where G03 is the value passed as argument while executing the script:


SRCFILE="THS_PROF.txt"
sed '1d' $SRCFILE | while read X; do
OUTFILE="THS_PROF_"`echo "$X" | awk -F"\t" '{ print $2 }'`"_"`date +%Y%m%d%H%M%S`".txt"
echo "$X" > $OUTFILE
# 23  
Old 01-14-2009
Hmm...I'm still trying to parse what you just said...

Ok so you'd like just one output and the output will contain what exactly?
# 24  
Old 01-14-2009
If the qry is returning 2 rows then the outptut file will contain those 2 rows.

For ex: If my file name is abc.sh
and while executing this abc.sh im passing an argument i.e.
sh abc.sh G03

then the output file name shld be like
THS_PROF_G03_20090114171434.txt

and it should contain the 2 rows:
D|44083669|0192652286|10866|1
D|44083455|0192300318|10867|1
# 25  
Old 01-14-2009
Ok! Now I get it...

OUTFILE="THS_PROF_$1_`date +%Y%m%d%H%M%S`".txt"
SRCFILE="THS_PROF.txt"
sed '1d' $SRCFILE | while read X; do
echo "$X" >> $OUTFILE
done

Didn't test it yet. But go try.
# 26  
Old 01-14-2009
ya it worked, jus double quotes were missing after $1_

OUTFILE="THS_PROF_$1_"`date +%Y%m%d%H%M%S`".txt"
SRCFILE="THS_PROF.txt"
sed '1d' $SRCFILE | while read X; do
echo "$X" >> $OUTFILE
done

But in the output file getting some unwanted values also along with the desired values.

Tried using sed to remove those lines but failed :-(

copiyng the code so if you can find out:

#!/bin/sh
sqlplus uname/pwd@dbname <<EOF

set wrap off
set feedback off
set pagesize 0
set verify off
set trimspool on
set linesize 5000
set heading off

spool /SYSTEM/custom/modules/testing/THS_PROF.txt

select 'D'||'|'||ciam.external_id||'|'||ciem.external_id||'|'||p.element_id||'|'||
case when (p.element_id in (select pcm.member_id from package_component_members pcm, package_components pc
where member_id in (10867,10866,10866,10867,10868,10866,10866,90014,90021)
and pcm.member_type=1
and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810,90014,90022)
and pc.component_id=pcm.component_id)) then '1'
end "A"
from customer_id_acct_map ciam, customer_id_equip_map ciem, product p, cmf c, dual
where ciam.account_no=p.billing_account_no
and ciem.subscr_no=p.parent_subscr_no
and p.billing_account_no=c.account_no
and c.account_no=ciam.account_no
and c.bill_period='$1'
and ciem.external_id_type=1
and ciam.external_id_type=1
and ciem.external_id_type=ciam.external_id_type
and p.element_id in (select pcm.member_id from package_component_members pcm, package_components pc
where member_id in (10867,10866,10866,10867,10868,10866,10866,90014,90021)
and pcm.member_type=1
and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810,90014,90022)
and pc.component_id=pcm.component_id);
spool off;
exit

EOF

OUTFILE="THS_PROF_$1_"`date +%Y%m%d%H%M%S`".txt"
SRCFILE="THS_PROF.txt"
sed '1d' $SRCFILE | while read X; do
echo "$X" >> $OUTFILE
done

sed -e '/SQL/d' $OUTFILE > THS_PROF.txt

sed -e '/2,21/d' $OUTFILE > THS_PROF.txt

sed -e '/D/d' $OUTFILE > THS_PROF.txt
# 27  
Old 01-14-2009
Hi ss,

Could you post the output so that we can see what lines need to be removed.
# 28  
Old 01-14-2009
the output of THS_PROF_G03_20090114192352.txt is:

SQL> $
SQL>
SQL> select 'D'||'|'||ciam.external_id||'|'||ciem.external_id||'|'||p.e
lement_id||'|'||$
SQL> select 'D'||'|'||ciam.external_id||'|'||ciem.external_id||'|'||p.element_id||'|'||
2 case when (p.element_id in (select pcm.member_id from package_comp
onent_members pcm, package_components pc$
2 case when (p.element_id in (select pcm.member_id from package_component_members pcm, package_components pc
3 where member_id in (10867,10866,10866,10867,10868,10866,10866,9001
4,90021)$
3 where member_id in (10867,10866,10866,10867,10868,10866,10866,90014,90021)
4 and pcm.member_type=1$
4 and pcm.member_type=1
5 and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810
,90014,90022)$
5 and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810,90014,90022)
6 and pc.component_id=pcm.component_id)) then '1'$
6 and pc.component_id=pcm.component_id)) then '1'
7 end "A"$
7 end "A"
8 from customer_id_acct_map ciam, customer_id_equip_map ciem, produc
t p, cmf c, dual$
8 from customer_id_acct_map ciam, customer_id_equip_map ciem, product p, cmf c, dual
9 where ciam.account_no=p.billing_account_no$
9 where ciam.account_no=p.billing_account_no
10 and ciem.subscr_no=p.parent_subscr_no$
10 and ciem.subscr_no=p.parent_subscr_no
11 and p.billing_account_no=c.account_no$
11 and p.billing_account_no=c.account_no
12 and c.account_no=ciam.account_no$
12 and c.account_no=ciam.account_no
13 and c.bill_period='G03'$
13 and c.bill_period='G03'
14 and ciem.external_id_type=1$
14 and ciem.external_id_type=1
15 and ciam.external_id_type=1$
15 and ciam.external_id_type=1
16 and ciem.external_id_type=ciam.external_id_type$
16 and ciem.external_id_type=ciam.external_id_type
17 and p.element_id in (select pcm.member_id from package_component_m
embers pcm, package_components pc$
17 and p.element_id in (select pcm.member_id from package_component_members pcm, package_components pc
18 where member_id in (10867,10866,10866,10867,10868,10866,10866,9001
4,90021)$
18 where member_id in (10867,10866,10866,10867,10868,10866,10866,90014,90021)
19 and pcm.member_type=1$
19 and pcm.member_type=1
20 and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810
,90014,90022)$
20 and pcm.component_id in (10459,10458,10658,20105,10499,10647,10810,90014,90022)
21 and pc.component_id=pcm.component_id);$
21 and pc.component_id=pcm.component_id);
D|44083641|0192300160|10866|1$
D|44083641|0192300160|10866|1
D|44083641|0192300160|10867|1$
D|44083641|0192300160|10867|1
SQL> spool off;$
SQL> spool off;


out of which i jus want:

D|44083641|0192300160|10866|1
D|44083641|0192300160|10866|1
D|44083641|0192300160|10867|1
D|44083641|0192300160|10867|1

but without $.

i tried sed but prob couldnt be resolved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace Stub Values In One Group Of Files With Actual Values From Another Group Of Files

I have two directories of files (new-config-files and old-config-files): new-config-files/this-db/config.inc.php new-config-files/that-db/config.inc.php new-config-files/old-db/config.inc.php new-config-files/new-db/config.inc.php new-config-files/random-database/config.inc.php etc. ... (4 Replies)
Discussion started by: spacegoose
4 Replies

2. Shell Programming and Scripting

Interpolation of two values in two different files

Dear All, I have two files which contain numerical data and strings. I want to create a new file that only revise numerical data from two files using interpolation. I guess AWK works, but I am new on AWK. FileA.txt . . index_2("0.1, 1, 2, 4, 8, 16, 32"); values("0.0330208, 0.0345557,... (17 Replies)
Discussion started by: jypark22
17 Replies

3. Shell Programming and Scripting

Comparing the values of two files

Hi Am trying to compare the values of two files.. One is a big file that has many values and the other is a small file.. The big file has all values present in small file.. # cat SmallFile 4456602 22347881 7471282 15859891 8257690 21954701 7078068 18219229 2883826 6094959 100000 ... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

5. Shell Programming and Scripting

Value falls between two values from different files

Hi, I have two files cat 1 100 1 110 2 113 4 230 5 334 7 500 8 900 10 I have another file cat 2 100 200 201 300 301 400 401 500 501 600 601 700 (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Summarize the values from files

One of my process will create a file Market.txt with data like below. Count Markt file 334936 /pdm/data001/P3_Quest_5HT_AMERGE.csv 2770787 /pdm/data001/P3_Quest_ARB_ATACAND.csv 1198143 /pdm/data001/P3_Quest_Bisp_ACTONEL.csv 3821864 /pdm/data001/P3_Quest_CONTRA_ALL_OTHER_CONTRA.csv... (7 Replies)
Discussion started by: katakamvivek
7 Replies

7. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

8. Shell Programming and Scripting

match 2 files by values

Hello ALL, Hope all fine for you. I have the following task but no idea about how to do. I have 2 files (ascii) one of them is a list of bib records, looks like this: =LDR 01228nam 2200301 b 4500 =001 00000000000001 =005 20090429:10082000 =008 ... (2 Replies)
Discussion started by: ldiaz2106
2 Replies

9. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

10. Shell Programming and Scripting

how to sum values from 2 different files?

Hi I am trying to add count values from two different files into one file. Could any body please suggest me best command to do this? My problem was as follows: a.txt b.txt c.txt 10 20 30(needed) i tried cat a.txt b.txt > c.txt (its not adding the values) Thanks in advance.. Praveen (8 Replies)
Discussion started by: npk2210
8 Replies
Login or Register to Ask a Question