Last word substitution


 
Thread Tools Search this Thread
Operating Systems Linux Last word substitution
# 1  
Old 06-04-2008
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 (
ZIP_CD ,
ZIP_TYP_SRC_CD ,
ZIP_TYP_CD ,
ZIP_ROW_END_DT ,
ZIP_ROW_EFF_DT ,
ZIP_LST_2_CD ,
ZIP_FST_3_CD ,
UPDT_DT WITH
ST_NUM_CD ,
ST_ABBR_CD ,
PST_CNTY_NM ,
PST_CNTY_CD ,
LOAD_DT WITH
HCFA_CNTY_NM ,
HCFA_CNTY_CD ,
CTY_NM ,

Desired output is

#cat zip.20080604.sql
CONNECT TO TST103 ;
SET SESSION_USER OPSDM001 ;
SET CURRENT SCHEMA OPSDM001 ;
CREATE VIEW OPSDM001.vw_zip SELECT (
ZIP_CD ,
ZIP_TYP_SRC_CD ,
ZIP_TYP_CD ,
ZIP_ROW_END_DT ,
ZIP_ROW_EFF_DT ,
ZIP_LST_2_CD ,
ZIP_FST_3_CD ,
UPDT_DT WITH
ST_NUM_CD ,
ST_ABBR_CD ,
PST_CNTY_NM ,
PST_CNTY_CD ,
LOAD_DT WITH
HCFA_CNTY_NM ,
HCFA_CNTY_CD ,
CTY_NM )

Thanks ,
# 2  
Old 06-04-2008
Code:
sed -i '$s/,/)/' zip.20080604.sql

# 3  
Old 06-05-2008
Thanks a lot !
# 4  
Old 06-09-2008
can you please tell me what is the significance of "-i" option in the command.???

i tried to find out but failed to get any info from net. Smilie
# 5  
Old 06-10-2008
Some versions of sed allow you to do edits in the file itself, without saving to a temporary file and then moving it back over the original file. Probably your sed doesn't have this option.

Please start a new thread if you have a tangential question.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 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. 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

7. Linux

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 . ... (6 Replies)
Discussion started by: capri_drm
6 Replies

8. 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

9. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 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