sed delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed delimiter
# 1  
Old 02-08-2012
sed delimiter

HI all,,
I hve defined something like

Code:
set data = /data/2012/text

while using
Code:
sed 's/$data//g'

I am getting error as:I understand this is due to / slash,but is there any way out of it....
Code:
sed: -e expression #1, char 12: unknown option to `s'

Thakns in adv.

Last edited by Franklin52; 02-08-2012 at 06:17 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-08-2012
Code:
sed "s:$data::g"

# 3  
Old 02-08-2012
$data is within single quotes, so in this case it would get interpreted literally as a $ sign followed by the letters data.
My guess is you were using double quotes and then you could do something like this:
Code:
sed "|$data||g"

instead of | you can use almost any character you like.
Code:
sed "#$data##g"

# 4  
Old 02-08-2012
Thanks for your effort but it is not helping
Code:
/data/2012/text/1
/data/2012/text/2
/data/2012/text/3
/data/2012/text/4
/data/2012/text/5
/data/2012/text/6

I just want to take out /data/2012/text ($data) out of those,tried ur command
Code:
sed "s:$data::g"

but got error as
Code:
Bad : modifier in $ (:).

please help

---------- Post updated at 01:38 AM ---------- Previous update was at 01:32 AM ----------

thanks all of u,
it worked with
Code:
sed 's:'"$data"'::g'


thanks a lot again!!!!
appreciated all ur help

Last edited by Franklin52; 02-08-2012 at 06:17 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 02-08-2012
Are you using csh or tcsh? Switch to sh/ksh/bash.
# 6  
Old 02-08-2012
Works for me.
Another alternative, if you want to remove string till the last slash, try this:
Code:
$ sed 's:.*/:/:g' inputfile
/1
/2
/3
/4
/5
/6

# 7  
Old 02-08-2012
thanks alot again all of you.
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 error

Hi, I'm having a bit of trouble replacing sed's delimiter from a slash to a pipe. This works... sed '/INSERT INTO/s/\${TD_LOAD_DB}/NUC_PL_LOAD/g' sql_file.sql But this doesn't sed "|INSERT INTO|s|\${TD_LOAD_DB}|NUC_PL_LOAD|g" sql_file.sql (2 Replies)
Discussion started by: c19h28O2
2 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