I'm modifying raw PCL/PS files (mixed) and for some reason I can't get my Sed syntax right for the true beginning that I want it to grab. Here's a sample output from the strings command:*c50B*c0P&f1X&f7y4X%-12345X%!PS-Adobe-3.0 EPSF-3.0 <------Sed doesn't work for this pattern%%Creator: tiff2ps  <----Sed works for this pattern[data...]%%EOFHere's my sed command that works:sed -n '/%%Creator/,/%%EOF/p'But I want it to start with %-12345X%:sed -n '/%-12345X%/,/%%EOF/p'When I do the last command, it just outputs the entire file. No combination from that line works. Now, I'm viewing the raw print file with 'strings', could it be that that line is encoded in a way that sed can't understand? Any idea on working around this?Edited to add:I'm pretty sure this has to do with the encoding of PCL and line escapes. The file goes from PCL to PS, and doesn't create the first message of PS on it's own line. Output of cat looks like this:*c50BESC*c0PESC&f1XESC&f7y4XESC%-12345X%!PS-Adobe-3.0 EPSF-3.0%%Creator: tiff2ps
Trouble with Sed Syntax
text processing;sed
My guess is that sed is doing exactly what you're telling it to do: Print out the first line that contains %-12345X%. But since this is not an ASCII file, but a PCL or PDF file with all sorts of binary bytes in there- and no proper newline to speak of, until just in front of %%Creator:- it prints out the entire thing. Remember, sed prints the matching line. What you're asking it to do, I think, is print starting at this string.If you want to take a file that's not guaranteed to be line-oriented (such as this), you're going to have to use a technique that does not depend on line-oriented tools. This may help: how to dump part of a binary file. It's a little more complicated but your strings are pretty distinctive so it should do the trick.Hmm... just had a idea- maybe this would work. It deletes everything on the same line that's in front of the %-12345X% except for that string itself. Then it prints everything from that line to the end of file. I haven't tried this, but that's how I'd approach it:sed -n -e '/%-12345X%/s/.*%-12345X%/%-12345X%/' -e '/%-12345X%/,/%%EOF/p'Or even better:STR=%-12345X%sed -n -e /${STR}/s/.*${STR}/${STR}/ -e /${STR}/,/%%EOF/p