sed usage


 
Thread Tools Search this Thread
Operating Systems Linux sed usage
# 1  
Old 05-16-2008
sed usage

Hi ,
I have a question. How do I replace 2 words in one line like this

IN CLO07 INDEX IN CLOIX07

to

IN CLO07_S02 INDEX IN CLOIX07_S02

But one thing to remember is that there are lots of words like CLODM001 .
So the only matching pattern is "IN CLO"

sample file is :

CREATE TABLE CLODM001.DIM_HOSPITAL (
HOSP_SYS_ID INTEGER NOT NULL ,
CONTR_MKT_NM VARCHAR(30) NOT NULL ,
CONTR_SUB_MKT_NM VARCHAR(30) NOT NULL
LOAD_DT DATE NOT NULL WITH DEFAULT CURRENT DATE ,
UPDT_DT DATE NOT NULL WITH DEFAULT CURRENT DATE )
COMPRESS YES
IN CLO07 INDEX IN CLOIX07 ;


I used this one but its not right right one .

sed -e 's/\(IN CLO[^"]*\)/\1_S02/g' db2look_DIM_HOSPITAL.ddl1 > db2look_DIM_HOSPITAL.ddl2

Thanks in advance ,
# 2  
Old 05-16-2008
Code:
sed -e 's/\(IN CLO[^ ]*\)/\1_S02/g'

should perhaps work better.
# 3  
Old 05-16-2008
Era,
It works fine for only one file. I am passing the many file for that change from CLO* to CLO*_S02 .
Here is the code part

if [ ${source_schema} = 'OPSDM001' ]
then
sed -e 's/\(TSO[^"]*\)/\1_S02/g' $TN.${ecmdate}.sql > $tmpfile_cln
sed -e 's/"//g' $tmpfile_cln > $TN.${ecmdate}.sql
elif [ ${source_schema} = 'DAYA' ]
then
sed -e 's/\(TEST[^"]*\)/\1_S02/g' $TN.${ecmdate}.sql > $tmpfile_cln
sed -e 's/"//g' $tmpfile_cln > $TN.${ecmdate}.sql
elif [ ${source_schema} = 'CLODM001' ]
then
sed -e 's/\(IN CLO[^ ]*\)/\1_S02/g' $TN.${ecmdate}.sql > $tmpfile_cln
sed -e 's/"//g' $tmpfile_cln > $TN.${ecmdate}.sql
elif [ ${source_schema} = 'UHCDM001' ]
then
sed -e 's/\(TSHL[^"]*\)/\1_S02/g' $TN.${ecmdate}.sql > $tmpfile_cln
sed -e 's/"//g' $tmpfile_cln > $TN.${ecmdate}.sql
else
echo " hi "
fi

This script works fine for other schemas but CLODM001 is not working at all. Am I missing something here too ?

Thanks for yoor help !
# 4  
Old 05-16-2008
Where are the double quotes coming from, you are removing double quotes after the basic substitution, which suggests that something is adding double quotes somewhere earlier in the script. Then maybe the substitution should be different, too. If all the others are working then maybe you need to have ^" there after all. Or if you have double quotes in or around "IN" too then obviously they need to be taken into account.
# 5  
Old 05-16-2008
You are right Era ,
I moved the file cleaning before CLO part and it works fine now .

Thanks !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command usage

Hi, Can anyone let me know the sed command usage requirement: sed 's/standard/standard_and/' <new.txt>new.txt here it needs to search for the pattern "standard" in the file new.txt and it should replace as "standard_and" in the same file new.txt Note: new.txt is having a separator... (8 Replies)
Discussion started by: srikanth_sagi
8 Replies

2. Shell Programming and Scripting

sed usage with Variable

Gurus, I am trying to display a match (single character) from beginning of the line in a file using a variable. I tried using sed ... not sure where am doing it wrong... sed -n "/^\$variable/p" FileName.shor sed -n "/^\${variable}/p" FileName.shBoth of the above are not working.....Thanks... (4 Replies)
Discussion started by: Kevin Tivoli
4 Replies

3. Shell Programming and Scripting

'sed' usage error.

Friends, I came across a wierd scenario while using sed. When I use the below cmd sequence at OS prompt it works fine: sed 's/# TMOUT=120/TMOUT=900/g' /etc/profile > /etc/profile.011211 However when I use the same in a script it throws the following error: ==Error== sed: 0602-404... (4 Replies)
Discussion started by: thisissouvik
4 Replies

4. Shell Programming and Scripting

sed usage

Hi, I want to replace some character whenever there is a space using sed. Input file name: aaa command i am trying is sed 's/^$/A/g' aaa (2 Replies)
Discussion started by: rakeshbharadwaj
2 Replies

5. Shell Programming and Scripting

sed usage

Hi, I want to read a command value and replace the command value in another file. Anybody know how to write it??? For example: File A: Command1 = test File B: Command1 = Command2 = Command3 = I want to write a shell script to read content from File A and replace Command1... (3 Replies)
Discussion started by: linboco
3 Replies

6. Shell Programming and Scripting

Sed usage

How can i use sed to change "Linux Cpu (EDF).sh" to "LinuxCpuEDF.sh"? I want to replace the spaces and brackets. (4 Replies)
Discussion started by: proactiveaditya
4 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Shell Programming and Scripting

sed usage

I'd like to extract the temps from the following command via a series of sed statements but the actual syntax is beyond me. $ nc localhost 7634 ... (2 Replies)
Discussion started by: audiophile
2 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

possible sed usage

Sorry about the title. I'm assuming I want sed anyway... Here's the deal: I have hundreds of files in a folder and they all are named with the same format. $NAME-$VERSION-$ARCH-$BUILD This is Slackwares' /var/log/packages directory BTW... $BUILD is what I'm focusing on. It could be... (6 Replies)
Discussion started by: madpenguin
6 Replies
Login or Register to Ask a Question