word substitution in unix


 
Thread Tools Search this Thread
Operating Systems Linux word substitution in unix
# 1  
Old 05-07-2008
word substitution in unix

Hi I am trying to substitute 2 words on the same line with _S02 as suffix. Like this .

IN "TSOPS09" INDEX IN "TSOPIX09" ;

to

IN "TSOPS09_S02" INDEX IN "TSOPIX09_S02" ;

i used the following code to make the change , it works fine for first substitution not the second one .

TBLSP_NM=` cat db2look_FACT_PHYSICIAN.ddl | grep -i TSOP | awk '{print $2}' | cut -d '"' -f 2 `
echo $TBLSP_NM
sed -e 's/'${TBLSP_NM}'/'${TBLSP_NM}'_S02/g' db2look_FACT_PHYSICIAN.ddl

the output comes as

IN "TSOPS09_S02" INDEX IN "TSOPIX09" ;


Any help is appreciated !
# 2  
Old 05-07-2008
Code:
echo 'IN "TSOPS09" INDEX IN "TSOPIX09" ; ' | sed 's/"\([^"][^"]*\)"/"\1_S02"/g'

# 3  
Old 05-07-2008
vgersh preceded me, anyway another one:

Code:
sed 's/\(TSOP[^"]*\)/\1_S02/g' db2look_FACT_PHYSICIAN.ddl

# 4  
Old 05-07-2008
Thanks a lot ! You guys rock !!!
# 5  
Old 05-07-2008
Hi,
I ahve next question . I have script which gets info from db2 engine.
The script is

cat sample_substitute.sh
CNTR_NM=`db2 -x "select CONTAINER_NAME ,usable_pages from table( SNAPSHOT_CONTAINER('TST103',-1)) as SNAPSHOT_CONTAINER, syscat.tablespaces where
tablespace_name = tbspace and tbspacetype = 'D' and tbspace='TSOPS06'" `
echo ${CNTR_NM}

The output is like this

/dmpath/dmtiadm1/db2fs1p00/tsops06 2128

But I am trying to get the output like this

'/dmpath/dmtiadm1/db2fs1p00/tsops06' 2128

i.e. the string inside the single quote.

Thanks again in advance !
# 6  
Old 05-08-2008
You may use a thing like:

Code:
echo "${CNTR_NM}" | sed "s/\([^ ]*\)/'\1'/1"

or

Code:
echo "${CNTR_NM}" | awk '{ printf("\047%s\047 %s\n", $1, $2) }'


On Solaris, use nawk instead of awk.
# 7  
Old 05-14-2008
i started a new thread for next problem

Last edited by capri_drm; 05-14-2008 at 04:28 PM.. Reason: starting a new thread
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. UNIX for Dummies Questions & Answers

Word-counting and substitution with awk

Hi!! I am trying to write a program which allows me to count how many times I used the same word in a text: {$0 = tolower ($0) gsub (/_]/, "", $0) for (i = 1; i <= NF; i++) freq++ } END { for (word in freq) printf "%s\t%d\n", word, freq It seems work but... (3 Replies)
Discussion started by: ettore8888
3 Replies

3. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

4. Shell Programming and Scripting

Help with word substitution

Hi all, I am trying to write a script substituting one word in a particular file with another word (sed) but I'm having trouble creating the backup file. The following are my instructions: The Unix program sed is useful for making simple substitutions throughout an entire file. But one of... (0 Replies)
Discussion started by: Hoppy56
0 Replies

5. Shell Programming and Scripting

whole word substitution in SED

I am trying to substitute something with sed and what I want is to substitute a whole word and not part of a word. ie sed 's/class/room/g' filename will substitute both class and classes into room and roomes which is not what i want Grep for instance can use the -w option or <> grep -w... (7 Replies)
Discussion started by: gikay01
7 Replies

6. Shell Programming and Scripting

Unix Variable Reference and Substitution

I can't seem to make what appears to be a simple substitution. I want to define a list of systems for which daily reports need to be filed systems="systemA systemC systemZ" I then want to run a loop for i in ${systems} Analyze statistics Create the reports mailx (8 Replies)
Discussion started by: mugsymark
8 Replies

7. Linux

Multiple files and word substitution

Hi , I have bunch of sql file which contain UHCDEV01 in them . I want to replace all the UHCDEV01 with UHCETL01 in all the files. I have written this code which shows correct output on sh -x but doesn't change the output file . #cat change_dbname.shl #!/bin/ksh... (1 Reply)
Discussion started by: capri_drm
1 Replies

8. Linux

Last word substitution

Ok this is last question of the day from my side . I have this file and I want to replace the last letter " , " with " ) " . The input file is #cat zip.20080604.sql CONNECT TO TST103 ; SET SESSION_USER OPSDM001 ; SET CURRENT SCHEMA OPSDM001 ; CREATE VIEW OPSDM001.vw_zip SELECT ( ... (4 Replies)
Discussion started by: capri_drm
4 Replies

9. Shell Programming and Scripting

How to use sed substitution using a $variable for a line containing a word

$ cat ggg /E*Fare/testteam/public/pf3/nggfstatic/4k-pf3_3.case REGION1: /E*Fare/dist/src/nggfstaticbase/EFare/Server CODEBASE1: /dev_tools/LINUXMTP-4/EFS070718E/EFare/Server DATABASE1: nggfstatic SCRIPT: /efare1/admin/ezlcn/scripts/pf3_3_scriptlist.input PROLOGINITSIZE not yet set You... (4 Replies)
Discussion started by: Sangal-Arun
4 Replies

10. Shell Programming and Scripting

word substitution in csh

I have data that looks something like this: term1/term2/2005-12-01 13:20:30/term4 I need to make it look like this: term1/term2/20051201132030/term4 I am using a csh script. I have tried to do it by first converting the date/time to the format in which I want it, and then replacing it... (1 Reply)
Discussion started by: oprestol
1 Replies
Login or Register to Ask a Question