I have a text file that I want sed to add a few lines to right before an existing line.

What I want to add is:

currentpagedevice /InputAttributes get 0 get
dup null eq
{ pop }
{ dup length 1 add dict copy
dup /InputAttributes
1 dict dup /Priority [0 1 2 3] put
put setpagedevice
} ifelse

And I want it right before the line containing the following:

Page: 1 1

Here's what I have in a file called sedscript.sed, but it doesn't seem to do anything..:

s#Page: 1 1#\
\i\ncurrentpagedevice /InputAttributes get 0 get\ndup null eq\
\n{ pop }\n{ dup
length 1 add dict copy\
\ndup /InputAttributes\
\n1 dict dup /Priority [0 1 2 3] put\
\nput
setpagedevice\
\n} ifelsei#

Here's how I call it:
sed -f sedscript.sed def011.txt

Thanks for your help in advance.

I updated it a little, but still nothing happens.:

s@\(*Page: 1 1*$\)@\
\ncurrentpagedevice /InputAttributes get 0 get\
\ndup null eq\
\n{ pop }\
\n{ dup length 1 add dict copy\
\ndup /InputAttributes\
\n1 dict dup /Priority [0 1 2 3] put\
\nput setpagedevice\
\n} ifelsei\
\n\1@

zsh 4.3.4% echo "Page 1 1"|sed '/Page 1 1/i\
currentpagedevice /InputAttributes get 0 get\
dup null eq\
{ pop }\
{ dup length 1 add dict copy\
dup /InputAttributes\
1 dict dup /Priority [0 1 2 3] put\
put setpagedevice\
} ifelse'
currentpagedevice /InputAttributes get 0 get
dup null eq
{ pop }
{ dup length 1 add dict copy
dup /InputAttributes
1 dict dup /Priority [0 1 2 3] put
put setpagedevice
} ifelse
Page 1 1

Cool thanks, so working with what you gave me. I tried to make this work with my file so I put it in the script as:

/*Page: 1 1*/i\
currentpagedevice /InputAttributes get 0 get\
dup null eq\
{ pop }\
{ dup length 1 add dict copy\
dup /InputAttributes\
1 dict dup /Priority [0 1 2 3] put\
put setpagedevice\
} ifelse

Then I ran the script with:

sed -f sedscript.sed def011.txt

But it still does not do anything...

You will get the modified output, you just have to save it,
or, if you have the GNU sed, you could use the -i switch to modify the file in-place.

I went like this:

sed -f sedscript.sed def011.txt>output.txt

No change was made.

Here's what the line looks like that I'm putting this stuff in front of. Its a postscript file that I'm editting in actuallity if that matters.

%%Page: 1 1

lol, so I tried to copy and paste that exact string in instead of the reg exps and it seemed to start working. Thanks for all the help.

Now if only I could get my postscript file to print some pages from one print tray and then some pages from another, all within the same printjob. I have the code that seems to change the tray, but it only wants to do it once.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.