Another substitution problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another substitution problem
# 1  
Old 12-10-2010
Another substitution problem

Hello again,

I'm trying to change the following line:

Code:
 
INSERT INTO PH1_TX_LOAD VALUES ('TX-78731-AABSS:4182-4','RH: GUIDE TO TENNIS',TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),TO_DATE('21-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),500)

so that any TO_DATE is taken out and just the date left, i.e

TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS')

to

'18-JUN-2001'

I have tried the following:

Code:
sed "s/TO_DATE(\(*:\)/\1/g"  inputfile

Which doesn't work, what are the errors with it?
# 2  
Old 12-10-2010
Your insert query contains 2 occurrence of TO_DATE statements. So, if you will use g at the end of sed command to date value after TO_DATE then it will return the second date(i.e 21-JUN-2001). Because, the sed parser checks the greedy pattern matching.

So don't include g at the end. Try following command

Code:
sed "s/TO_DATE('\(.*\)'/\1/" inputfile | cut -d":" -f1

R0H0N
# 3  
Old 12-10-2010
If I don't include g will only the first instance be changed?
Essentially I want to change:

Code:
INSERT INTO PH1_TX_LOAD VALUES ('TX-78731-AABSS:4182-4','RH: GUIDE TO TENNIS',TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),TO_DATE('21-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),500)

to

Code:
INSERT INTO PH1_TX_LOAD VALUES ('TX-78731-AABSS:4182-4','RH: GUIDE TO TENNIS','18-JUN-2001','21-JUN-2001', 500)

When I use

Code:
sed "s/TO_DATE('\(.*\)'/\1/" inputfile > output

it appears that I need to remove the of the string in the brackets as it comes up with

Code:
 
18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS')

# 4  
Old 12-10-2010
Code:
sed "s/^\(.*\),TO_DATE('\([0-9][0-9]-[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9]\).*),TO_DATE('\([0-9][0-9]-[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9]\).*')\(.*\)/\1,'\2','\3'\4/g" inputfile

R0H0N
# 5  
Old 12-10-2010
If date format is fixed and always like blow:
Code:
TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS')

i.e. 57 characters overall then
Code:
sed "s/TO_DATE('\(...........\):\(....................................\)/\1/g" inputFile

Here dots in red are for date value (18-JUN-2001) - one dot for each character.
dots in green are for 00:00:00', 'DD-MON-YYYY:HH24:MI:SS').
# 6  
Old 12-10-2010
Code:
sed "s/TO_DATE(\('[^:]*\)[^)]*)/\1'/g" infile

# 7  
Old 12-10-2010
Much appreciated. Starting to get to grips with all this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Variable substitution problem

HI i was studying about variable substitution. below are info which was given in a online tutorial. ${parameter:-word}---> If parameter is null or unset, word is substituted for parameter. The value of parameter does not change. ${parameter:=word}---> If parameter is null or... (3 Replies)
Discussion started by: scriptor
3 Replies

2. Shell Programming and Scripting

Problem with process substitution

i have tried process substitution, but run in some problems. this works: samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count & but this not: htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf >... (7 Replies)
Discussion started by: dietmar13
7 Replies

3. Shell Programming and Scripting

Problem with substitution in sed??

Hi alll I have a file with this content ale,AAM,id2_1_2_1_1,23,2013-01-30,1,1 ale,BAND,id2_1_1_1_1,31,2013-01-28,1,1 ale,CAI,id2_1_1_1_1,23,2013-01-28,1,1 ale,CAI,id2_1_1_1_4,23,2013-01-28,1,1 ale,CAI,id2_1_2_1_1,23,2013-01-30,2,1 ale,NAST,id2_1_1_1_1,23,2013-01-29,1,1... (1 Reply)
Discussion started by: nikhil jain
1 Replies

4. Shell Programming and Scripting

sed substitution problem

I'm writing my first script and I have all the other commands I'm using working properly, but I'm having one final issue with a sed. I've looked on the forums for some answers, which have been close but sed is quite confusing to me. My problem is that I have a file called CylinderAtom1.txt... (3 Replies)
Discussion started by: 1Aegis1
3 Replies

5. Shell Programming and Scripting

problem in dollar substitution

Hi, I have a problem in dollar substitution:- $ csv1="first_csv" $ csvnumber=1 $ echo {csv$csvnumber} {csv1} $ echo "${csv$csvnumber}" bad substitution I want first_csv...why is it not working thanks (2 Replies)
Discussion started by: scripter12
2 Replies

6. Shell Programming and Scripting

Crontab command substitution problem

Hi all, I am using Ubuntu 8.04 Linux. I have a cron job entry to run a shell script at a scheduled time. This script has a X application to be launched. As cron does not pick already exported environment variables and it runs in a separate environment, I need to export the DISPLAY variable to... (9 Replies)
Discussion started by: royalibrahim
9 Replies

7. Shell Programming and Scripting

sed substitution problem

Can anyone please help me on this. i have a file with lines say X X3200 X X X X2400 X X4100 I want to use sed to put the numbers in braces. the output should be like, X X(3200) X X X X(2400) X X(4100) (7 Replies)
Discussion started by: diliphp
7 Replies

8. Shell Programming and Scripting

Problem with sed string substitution

Hi, heres my problem: echo "aaaa(aaaa(aaa" | sed 's/a.*(//g' gives aaa but it should give aaaa(aaa .*( should find any string to the appearance of (, but it finds any string to the last appearance, any idea why, and how to do this? and what if the string ist... (2 Replies)
Discussion started by: funksen
2 Replies

9. AIX

VI Substitution problem

I'm having a problem getting my variables to work in dishing out an RMC script. The $1 works fine. $2 does not Here's a portion of the script: server=$1 filesystem1=$2 # dsh -w $1 'mkcondition -c "/var space used" -s "Name == \"$2\"" -e "PercentTotUsed > 90" -d "An event will be generated... (7 Replies)
Discussion started by: gravy26
7 Replies

10. Shell Programming and Scripting

Substitution problem.

Hi, Just need some help in this. Suppose there is one file a.txt, which contains this data: "25187","00000022","00",28-MAR-2007,"" ,"D",-000001550,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ,29-MAR-2007 613TB.STEXTRF1 "25187","0000004H","00",29-MAR-2007,""... (3 Replies)
Discussion started by: er_ashu
3 Replies
Login or Register to Ask a Question