Bash script for editing contents of one file according to other
hi
all let suppose I have two files: test1 and test2. I am giving you some part of that files. test1 <DefaultPrinter kkp> Info Location DeviceURI ipp://192.168.10.22:9100 state Idle ........ ....... and test2 ...some text ...... some text.... default_printer pal printer "pal" { location model ...... ... Interface_args {"REMOTE_PORT" = "9100", "REMOTE_HOST" = "192.168.10.251" } I want to read next string from default_printer and next string from REMOTE_HOST from test2 file and edit test1 file (by replacing next string from DefaultPrinter and next string from ipp://. How can I do these things? |
Code:
#!/bin/bash I wasn't entirely clear on which parts you wanted where, but I think that's it and the principle should work, whatever the details. |
It occurs to me that posting some output might help let you know if I was in the ballpark or not. (Red stuff is changed.)
Code:
pal |
hi
It gives me error: sed: -e expression #1, char 28: unterminated `s' command and How to extract "}" from rh. and I want o/p like: <DefaultPrinter pal> DeviceURI ipp: 192.168.10.251:9100 Thanks KKPal |
Quote:
I'm not sure what you mean about 'extract "}"' but the following changes the '<DefaultPrinter' bit like you say. The DeviceURI you list (192.168.10.251:9100) is what was in the original. If that's what you want, just don't do anything to it. Code:
:cat kkpal Code:
:cat kkpal |
hi Digiot
Thanks for quick reply. I am giving you full details what I want to do. I am writing a code for installing printer. For that I am I run "xpdq" and configure my printer. xpdq stores the configuration in its "printrc" file. According to printrc file I have to edit /etc/cups/printers.conf file. First I have to read default_printer name and IP address from "printrc" file. And edit the printers.conf file. I have to change DefaultPrinter name and IP address. I giving you complete files printers.conf # Printer configuration file for CUPS v1.1.23 # Written by cupsd on Wed Jul 11 13:08:38 2007 <DefaultPrinter kkp> Info Location DeviceURI ipp://192.168.10.22:9100 State Idle Accepting Yes JobSheets none none QuotaPeriod 0 PageLimit 0 KLimit 0 </Printer> printrc # Redefinitions are silently ignored. Be careful to define last the # choices you want. The order of processing is /etc/pdq/printrc and # then ~/.printrc ######################################################################## # # Configurable options # # # Directory to store jobs #job_dir "~/.printjobs" # Time (in seconds) for which job files will be saved. # Jobs files will be cleaned up after new jobs finish. #job_history_duration 259200 job_history_duration 3600 # Maximum number of times to try to connect to the printer. #max_send_tries 30 # Delay (in seconds) between attempting to resend #delay_between_tries 10 # Default printer definition #default_printer pokey # Path that gets passed to driver scripts driver_command_path "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" # Path that gets passed to interface scripts interface_command_path "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" ######################################################################## # # Extra pieces of this config file, that define drivers and interfaces. # # try_include "/etc/pdq/interfaces/*" try_include "/etc/pdq/drivers/*/*" default_printer komalpal printer "niv" { # Added by the wizard on Mon Feb 25 21:02:18 2008 location "nivio" model "hp3390" driver "generic-postscript" interface "tcp-port" driver_opts { } driver_args {"COPIES" = "1"} interface_opts { } interface_args {"REMOTE_PORT" = "9100", "REMOTE_HOST" = "192.168.10.251"} } How can I do that ? |
Code:
:cat kkpal -- Actually, made a few more changes to make it more consistent and readable, even though there's not much there to read. :) |
hi
this line is not changed "DeviceURI ipp://192.168.10.22:9100" I am getting only "DeviceURI ipp:192.168.10.251" I need "DeviceURI ipp://192.168.10.251:9100" I changed this line s,\(^DeviceURI// ipp:\).*,\1 $rh:9100, its working fine. I want to know I did write thing? Thanks KKPal |
Sorry, I don't even own a printer, but I see what you mean about the port number now. As far as whether you did the right thing, if it works, you did the right thing. :) But it seems that would work as long as it was always 9100. I see now that REMOTE_PORT is also in the interface_args so maybe adding the
Code:
rp=$(awk -vFS='[=,]' '/^interface_args/{ gsub(/["} ]/,""); print $2 }' printrc) Code:
s,\(^DeviceURI ipp:\).*,\1 $rh:$rp, -- This should be better: Code:
#!/bin/sh |
All times are GMT -5. The time now is 01:23 AM. |