Sponsored Content
Top Forums Shell Programming and Scripting using a another delimiter with sed? Post 302510300 by alister on Saturday 2nd of April 2011 09:44:42 PM
Old 04-02-2011
Quote:
Originally Posted by ahamed101
Code:
result=`sed -n -e "!^$line$!{x;p;q;};h" services.txt`


Quote:
Originally Posted by MastaG
Well I tried to use another delimiter but it seems to be unsupported.
The / works:
Code:
sed -n -e "/^Nederland 1$/{x;p;q;};h" services 
1f44:ffff0000:0008:01f4:1:331

However using ! will not:
Code:
sed -n -e "!^Nederland 1$!{x;p;q;};h" services
sed: Unsupported command ^

The sed program comes with busybox, maybe it differs from gnu-sed in a way that it doesn't support other delimiters?

That's not how alternative delimiters work for addresses. You must precede the opening delimiter with a backslash.

Code:
sed -n '\!reg_ex_here!p'

As opposed to its usage in a substitution command which does not use the preceding backslash at the beginning:
Code:
sed -n 's!reg_ex_here!&!p'

Also, you may want to keep in mind that the exclamation point introduces history expansion in some shells, even when in double quotes.

Regards,
Alister

Last edited by alister; 04-02-2011 at 10:57 PM..
This User Gave Thanks to alister For This Post:
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 02:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy