sed delimiter error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed delimiter error
# 1  
Old 05-26-2013
sed delimiter error

Hi,

I'm having a bit of trouble replacing sed's delimiter from a slash to a pipe.

This works...

Code:
sed '/INSERT INTO/s/\${TD_LOAD_DB}/NUC_PL_LOAD/g' sql_file.sql

But this doesn't

Code:
sed "|INSERT INTO|s|\${TD_LOAD_DB}|NUC_PL_LOAD|g" sql_file.sql

Although if i remove the INSERT INTO pattern, the delimiter works...

Code:
sed 's|\${TD_LOAD_DB}|NUC_PL_LOAD|g' sql_file.sql

Any ideas?
# 2  
Old 05-26-2013
Quote:
Originally Posted by c19h28O2
Hi,

I'm having a bit of trouble replacing sed's delimiter from a slash to a pipe.

This works...

Code:
sed '/INSERT INTO/s/\${TD_LOAD_DB}/NUC_PL_LOAD/g' sql_file.sql

But this doesn't

Code:
sed "|INSERT INTO|s|\${TD_LOAD_DB}|NUC_PL_LOAD|g" sql_file.sql

Although if i remove the INSERT INTO pattern, the delimiter works...

Code:
sed 's|\${TD_LOAD_DB}|NUC_PL_LOAD|g' sql_file.sql

Any ideas?
When using a character other than slash character ("/") as the delimiter in a context address, the first delimiter must be preceded by a backslash character ("\"), so try:
Code:
sed "\|INSERT INTO|s|\${TD_LOAD_DB}|NUC_PL_LOAD|g" sql_file.sql

Since there is no / in "INSERT INTO", why not use the default delimiter? (Note that the delimiter used for the context address and the delimiter used in the substitute command do not have to be the same character.)

Assuming that you're trying to search for the string specified by the variable TD_LOAD_DB, why do you have the backslash before the dollar sign?
These 2 Users Gave Thanks to Don Cragun For This Post:
# 3  
Old 05-26-2013
Thanks Don, that's exactly what I needed.

The final version of this will use a variable which all contain backslashes. Also I backslashed the dollar as that is what I am searching for Smilie

Thanks for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX sed use space as delimiter

I am trying to do this with one small tweak. I would also like to use a space as a delimiter. sed 's/ */\ /g' file This is what my file looks like. server1, server2, server3 server4 server5 server6 I would like it to look like this. server1 server2 server3 server4 ... (6 Replies)
Discussion started by: cokedude
6 Replies

2. UNIX for Beginners Questions & Answers

How to identify delimiter to find and replace a string with sed?

I need to find and replace a date format in a SQL script with sed. The original lines are like this: ep.begin_date, ep.end_date, ep.facility_code, AND ep.begin_date <= '01-JUL-2019' ep.begin_date, ep.end_date, ep.facility_code, AND ... (15 Replies)
Discussion started by: duke0001
15 Replies

3. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

4. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

5. Shell Programming and Scripting

sed delimiter

HI all,, I hve defined something like set data = /data/2012/text while using sed 's/$data//g' I am getting error as:I understand this is due to / slash,but is there any way out of it.... sed: -e expression #1, char 12: unknown option to `s' Thakns in adv. (6 Replies)
Discussion started by: Indra2011
6 Replies

6. Shell Programming and Scripting

Help with sed to add delimiter to send HEX with netcat

Hello, I want to send tcpflow dump to a TCP port in HEX data, to send with netcat i need to convert to HEX and add \\x before each HEX bytes, to do this i use this line: tcpflow -i -C dst port | xxd -p | sed 's/../&\\\\x/g;s/ $//' | nc the output on the listening end:... (3 Replies)
Discussion started by: patx
3 Replies

7. Shell Programming and Scripting

using a another delimiter with sed?

Hi there, After lots of reading I figured out how to use sed to parse my file. This file is called services.txt: 00a1:ffff0000:0018:01f4:1:477 BravaNL 00a2:ffff0000:0018:01f4:1:471 MAX 00a3:ffff0000:000b:01f4:1:390 HaberTürk... (5 Replies)
Discussion started by: MastaG
5 Replies

8. Shell Programming and Scripting

Implement in one line sed or awk having no delimiter and file size is huge

I have file which contains around 5000 lines. The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters. I want to delete the lines a> if it starts with 1 and if 576th postion is a digit i,e 0-9 or b> if it starts with 0 or 9(i,e header and footer) ... (4 Replies)
Discussion started by: millan
4 Replies

9. Shell Programming and Scripting

help with sed to add delimiter and new field to each row

I have a file with millions of rows that I need to add a delimiter and a new field with a zero to the end of each row. (its too big to open and do a find and replace regex) I'm looking for the next line '\n' and need to replace it with a Unit Separator (hex \037) 0 \n. I've tried the... (2 Replies)
Discussion started by: kmac
2 Replies

10. Shell Programming and Scripting

awk,nawk,sed, delimiter |~|

RECORD=NEW|~|VENDORN=LUCENT|~|VENDORM=CBX500_REAR|~|NETWORK=ATM|~|SUBNETWORK=N/A|~|SITE=CIL|~|REGION=KN|~|COUNTRY=PS|~|SWITCH=SWITCH1|~|E THERNET=N/A|~|LOOPBACK=N/A|~|SHELF=N/A|~|SLOT=14|~|SUBSLOT=N/A|~|STSCHAN=N/A|~|PORT=S14|~|DS1SLOT=N/A|~|LINE=N/A|~|LPORTID=N/A|~|CARDDESC=N/A|~|CARDTYPE=BAC2RT0... (7 Replies)
Discussion started by: knijjar
7 Replies
Login or Register to Ask a Question