General TC > Programming & Scripting - Unofficial

Need help with a scripting problem

(1/1)

PingPing:
I'm still on my L-plates when it comes to scripting so I was hoping someone can show me how to do this:
In my /etc/cups/mime.convs file there is a line:

#application/octet-stream     application/vnd.cups-raw    0     -

which I would like to change to:

application/octet-stream     application/vnd.cups-raw    0     -

How do I do this?  At the moment I'm just removing the whole mime.convs file and replacing it with one I'e prepared earlier.  However, I want to do the whole edit within the script (if possible) so if anyone can help I'd appreciate it.

^thehatsrule^:
You can use sed with something like (untested)
--- Code: ---sed -i 's/^#\(rest_of_line_to_search_for\)$/\1/' myfile
--- End code ---

PingPing:
Thanks.  I'll have to do some more research on this 'sed' command.  It looks pretty nifty.

danielibarnes:
Here is another method:
sed '/vnd\.cups-raw/s/^#//' -i myfile

It instructs sed to find the line containing 'vnd.cups-raw' and remove the leading #.

Here are a couple links I use:
http://www.grymoire.com/Unix/Sed.html#uh-15
http://www.unixguide.net/unix/sedoneliner.shtml

Edit: escaped "." in search expression.

^thehatsrule^:

--- Quote from: danielibarnes on June 19, 2009, 04:57:55 PM ---sed '/vnd.cups-raw/s/^#//' -i myfile

It instructs sed to find the line containing 'vnd.cups-raw' and remove the leading #.

--- End quote ---
That would need to be escaped, i.e. \.

Navigation

[0] Message Index

Go to full version