If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > sed/awk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-09-07, 19:43
usc usc is offline
Registered User
 
Join Date: Apr 2007
Posts: 21
sed/awk

i have file containing lines such as

Char(Month(L.prd_cvrg_end_dt)) =
STRIP(substr(V_MON_YR,1,2),L,'0')
AND Char(Year(L.prd_cvrg_end_dt))

which i need to change as:

Char(Month(L.prd_cvrg_end_dt)) =
STRIP(substr(V_MON_YR,1,2),'L','0')
AND Char(Year(L.prd_cvrg_end_dt))

how do i get this done.

i.e. change only the character ,L, to ,'L',

i attempted using sed/awk it looks like i have an error.

Last edited by usc; 05-09-07 at 19:51.
Reply With Quote
  #2 (permalink)  
Old 05-10-07, 04:26
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Code:
cat in-file | sed -e 's/,L,/,'L',/g' > out-file
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 05-10-07, 12:48
usc usc is offline
Registered User
 
Join Date: Apr 2007
Posts: 21
the single quote didn't make the changes.

tried double quote(") instead of single quote('), it works

cat t1 | sed -e "s/,L,/,'L',/g" > t2

Last edited by usc; 05-10-07 at 12:54.
Reply With Quote
  #4 (permalink)  
Old 05-11-07, 07:39
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
yeah single quote will cause an error
i.e.
cat in-file | sed -e 's/,L,/,'
then L
then ',/g' > out-file

I'm not 100% on sed but i would imagine you could delimit that to give you :
cat in-file | sed -e 's/,L,/,\'L\',/g' > out-file
Reply With Quote
  #5 (permalink)  
Old 05-11-07, 16:37
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Right. Escaping the nested single quotes will work. This is not an sed thing but rather the shell takes care of the escaping.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 05-31-07, 00:05
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
Originally Posted by usc
the single quote didn't make the changes.

tried double quote(") instead of single quote('), it works

cat t1 | sed -e "s/,L,/,'L',/g" > t2
...and why exactly do you need a 'cat'?
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On