sed/awk changing values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed/awk changing values
# 1  
Old 09-01-2011
sed/awk changing values

Can somebody help me out and provide me with a SED or AWK solution that converts TO_DATE CLAUSE -> TIMESTAMP

I need to keep the PARTION value (HISTORY_20110417) and DATE/TIME value (2011-04-18 00:00:00) the same for every line

Code:
 
PARTITION HISTORY_20110417 VALUESLESSTHAN(TO_DATE(' 2011-04-18 00:00:00','SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
 
PARTITION HISTORY_20110417 VALUESLESSTHAN(TIMESTAMP' 2011-04-18 00:00:00')
 

Thanks in advance to all who answer
# 2  
Old 09-01-2011
Is Perl OK?
Code:
perl -F"," -nae '$F[0]=~s/TO_DATE\((.*)/TIMESTAMP\1)\n/;print $F[0]' file

or shorter:
Code:
perl -pe 's/TO_DATE\(([^,]+).*/TIMESTAMP\1)/' file


Last edited by bartus11; 09-01-2011 at 02:41 PM..
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 09-01-2011
bartus thanks
# 4  
Old 09-02-2011
using nawk..
Code:
$ nawk -F"[(,)]" '{print $1"(TIMESTAMP"$3")"}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing values in the first column.

I have a file which looks like this: 1 3 5 5 3 2 1 5 3 6 3 2 0 5 6 3 2 9 0 4 5 6 4 9 In the first column, instead of 1, I want to place +1 and instead of 0, I want -1 to be put. So the generated file should look like this: +1 3 5 5 3 2 +1 5 3 6 3 2 -1 5 6 3 2 9 -1 4 5 6 4 9 Just to... (9 Replies)
Discussion started by: shoaibjameel123
9 Replies

2. UNIX for Dummies Questions & Answers

Changing the values of a column using awk and gsub

Hi, I am using the following code to change NA to X in only the 5th column of my text file: awk '{gsub("NA","x",$5)}1' in.file > out.file How can I modify this code if I want to change NA to X in multiple columns of the text file (i.e. columns 5,6 and 7). Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

3. Shell Programming and Scripting

SED/AWK to edit/add field values in a record

Hi Experts, I am new to shell scripting. Need some help in doing one task given by the customer. The sample record in a file is as follows: 3538,,,,,,ID,ID1,,,,,,,,,,, It needs to be the following: 3538,,353800,353800,,,ID,ID1,,,,,COLX,,,,,COLY, And i want to modify this record in... (3 Replies)
Discussion started by: sugarcane
3 Replies

4. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

changing files content with sed or awk

Hi, Example File: (jumped, bumped, ) how to jumped, FROM tree; EXIT I have some hundreads of files like this with the different words and I want to remove the comma before the bracket and also I have to remove the comma before FROM word. I am trying to use this command : awk '... (5 Replies)
Discussion started by: rajshashi
5 Replies

6. UNIX for Dummies Questions & Answers

Changing Text with sed or awk

I'm changing some html code on multiple web pages and I need to match particular phrases but keep some text within each phrase. E.G. I need to change this line: <DIV id="heading">Description:</DIV> into <span class="hlred">Description:</span><br /> The text "Description:" may... (2 Replies)
Discussion started by: hal8000
2 Replies

7. Shell Programming and Scripting

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (3 Replies)
Discussion started by: yerruhari
3 Replies

8. UNIX for Dummies Questions & Answers

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

9. UNIX for Advanced & Expert Users

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

10. Shell Programming and Scripting

awk/sed script to read values from parameter files

Hi, I am writing a shell program that executes a lot of Oracle SQL Files on different databases based on the enviroment setting value. I am trying to design a parameter file where i can store the environment values for all the databases in the below format Environment File File Name... (6 Replies)
Discussion started by: rajan_san
6 Replies
Login or Register to Ask a Question