Help with sed command please.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 5
Reputation: asciiletters is an unknown quantity at this point 
Solved Threads: 0
asciiletters asciiletters is offline Offline
Newbie Poster

Help with sed command please.

 
0
  #1
Oct 2nd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 5
Reputation: asciiletters is an unknown quantity at this point 
Solved Threads: 0
asciiletters asciiletters is offline Offline
Newbie Poster

Re: Help with sed command please.

 
0
  #2
Oct 2nd, 2007
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@
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: Help with sed command please.

 
0
  #3
Oct 2nd, 2007
Shell Scripting Syntax (Toggle Plain Text)
  1. zsh 4.3.4% echo "Page 1 1"|sed '/Page 1 1/i\
  2. currentpagedevice /InputAttributes get 0 get\
  3. dup null eq\
  4. { pop }\
  5. { dup length 1 add dict copy\
  6. dup /InputAttributes\
  7. 1 dict dup /Priority [0 1 2 3] put\
  8. put setpagedevice\
  9. } ifelse'
  10. currentpagedevice /InputAttributes get 0 get
  11. dup null eq
  12. { pop }
  13. { dup length 1 add dict copy
  14. dup /InputAttributes
  15. 1 dict dup /Priority [0 1 2 3] put
  16. put setpagedevice
  17. } ifelse
  18. Page 1 1
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 5
Reputation: asciiletters is an unknown quantity at this point 
Solved Threads: 0
asciiletters asciiletters is offline Offline
Newbie Poster

Re: Help with sed command please.

 
0
  #4
Oct 2nd, 2007
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...
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: Help with sed command please.

 
0
  #5
Oct 2nd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 5
Reputation: asciiletters is an unknown quantity at this point 
Solved Threads: 0
asciiletters asciiletters is offline Offline
Newbie Poster

Re: Help with sed command please.

 
0
  #6
Oct 2nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 5
Reputation: asciiletters is an unknown quantity at this point 
Solved Threads: 0
asciiletters asciiletters is offline Offline
Newbie Poster

Re: Help with sed command please.

 
0
  #7
Oct 2nd, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 1371 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC