Sed bug in OS X?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sed bug in OS X?
# 1  
Old 05-30-2003
Sed bug in OS X?

I've been playing around with sed for a few days now and find that regular expressions never work inside sed s/// on Mac OS 10.2.5. Has anyone else bumped up against this problem?

For example, the "sed" segment of the following always fails no matter how items are escaped:


cd /path/to/directory
egrep -a '<([\w]+)[^>]*>[^<]*</\1>' *.JPG | sed 's/<\([^>]+\)>/tag_attributes: \1/g'


Short of using Perl and laboriously opening each file walking through every line in every file and using Perl's s/// operator, is there another tool for doing this sort of stuff purely in unix?

Thanks

Ken

Last edited by ktoz; 05-30-2003 at 12:15 PM..
# 2  
Old 05-30-2003
Could you explain further what you mean to accomplish with that line of code? Too confusing for me to decipher Smilie .. plus there's no -a option for the egrep command. And although egrep is used to search/display text from a file, it looks like you're using it on image files..
# 3  
Old 05-30-2003
Sed bug in OS X?

The actual line I'm using was more complex so I "simplified" it to the line in my original post:)

Actually what I'm doing is scanning jpeg files that have info entered in the Photoshop "file info" dialog box and extracting this info for inclusion in a database. The info I'm interested in is xml formatted with some Adobe namespace info.

This line works great for extracting the info:

egrep -a '<photoshop:([^>]+)>[^<]*</photoshop:\1>' "botanical-garden12-full.jpg"

yeilds lines like:

<photoshop:CaptionWriter>this is where the caption writer goes</photoshop:CaptionWriter>
<photoshop:Headline>this is where the headline goes</photoshop:Headline>
<photoshop:Instructions>this is where the instructions go</photoshop:Instructions>


If you then pipe it to sed to try and strip out the xml like so:

<egrep stuff from above...> | sed 's/<photoshop:\([^>]+\)>\([^<]*\)<\/photoshop:\1>/\1: \2>/g'

returns results as if the sed routine wasn't even there...

<photoshop:CaptionWriter>this is where the caption writer goes</photoshop:CaptionWriter>
<photoshop:Headline>this is where the headline goes</photoshop:Headline>
<photoshop:Instructions>this is where the instructions go</photoshop:Instructions>

I've tried various quotation, delimiter and escape styles on the above ("" as opposed to '', () as opposed to \(\) and s@@@ as opposed to s/// none of it produced the desired results.

I changed the search portion of the sed routine to a simple character class for testing and even that failed. The only thing that seems to work is a string literal.

Do you see any glaring errors in the above?

Thanks

Ken
# 4  
Old 05-30-2003
I'm still trying to come up with a better solution, but in the meantime, awk would work like this:

<output from egrep...> | awk -F">" '{print $2}' | awk -F"<" '{print $1}'

Last edited by oombera; 06-04-2003 at 10:41 PM..
# 5  
Old 05-30-2003
Sed bug in OS X?

Hmmm... My turn to be puzzled. No idea what your example is doing, but I'll go read up on awk...

Ken
# 6  
Old 05-30-2003
What shell are you using?
# 7  
Old 05-30-2003
Sed bug in OS X?

tcsh for most stuff but the main script is running in sh (which I think is bash on OS X) not sure about that though.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Help in memcmp (it may be a bug)

Hello friends today i have created a program that is working fine . but when string becomes equal it does not work . /* String.h header series Comparison function memcmp = return 0 if string equal else return less or greater than value by comparing pointer first and pointer second ... (6 Replies)
Discussion started by: rink
6 Replies

2. Programming

is this a bug of g++?

Hello, Im using the g++(g++ Ubuntu/Linaro 4.4.4-14ubuntu5 4.4.5) and im trying to compile a small snippet code and got into an endless loop.I recompiled that in VS2010 under Windows 7 and the answer is as expected.so i wonder is this a bug of g++?here is my code. #include<iostream> using... (5 Replies)
Discussion started by: homeboy
5 Replies

3. UNIX for Dummies Questions & Answers

where's the bug?

#!/bin/bash if then #echo "infinite loop" exit 0 fi when I run this file I get the following error: ./test_infinite_loop: line 5: syntax error near unexpected token `fi' ./test_infinite_loop: line 5: `fi' :confused: (4 Replies)
Discussion started by: jon80
4 Replies

4. AIX

bug in 43 ???

xxxxserver# lsattr -El inet0 | grep 255.240.0.0,32.224.0.0,32.78.120.254 | grep '.40' route net,-hopcount,1,-netmask,255.240.0.0,32.224.0.0,32.78.120.254 How this is possible? (1 Reply)
Discussion started by: itik
1 Replies

5. Shell Programming and Scripting

Is it a bug ..?

Hi All, I am using Red Hat Linux on my servers. The problem that I am facing is, sometimes the /opt usage on the server shows used percentage as 100% , when actually it is simply 20%. When I reboot the system, it comes back to 20%.Is this a bug in the system or my settings have gone wrong... (1 Reply)
Discussion started by: nua7
1 Replies

6. UNIX for Advanced & Expert Users

logrotate bug?

I have been mailing myself logs for a while, but just ran into a problem because of a process that cannot HUP its log. (I realize thats why they implemented the "copytruncate" option in the first place) When I use logrotate with "copytruncate" and "compress" there is a problem. The "myScript"... (0 Replies)
Discussion started by: jjinno
0 Replies

7. UNIX for Dummies Questions & Answers

SED.EXE Bug?

Hi all, when using sed to replace a piece of text multiple times in a file something weird happens.If there is no carriage return after the last line in the file it deletes the line. Anyone know why ? Thanks Paul command line : sed -e "s/System.out.println/\/\/Commented out by us... (6 Replies)
Discussion started by: madcyril
6 Replies
Login or Register to Ask a Question