Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: PingPing on June 18, 2009, 01:25:03 PM
-
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.
-
You can use sed with something like (untested)
sed -i 's/^#\(rest_of_line_to_search_for\)$/\1/' myfile
-
Thanks. I'll have to do some more research on this 'sed' command. It looks pretty nifty.
-
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.grymoire.com/Unix/Sed.html#uh-15)
http://www.unixguide.net/unix/sedoneliner.shtml (http://www.unixguide.net/unix/sedoneliner.shtml)
Edit: escaped "." in search expression.
-
sed '/vnd.cups-raw/s/^#//' -i myfile
It instructs sed to find the line containing 'vnd.cups-raw' and remove the leading #.
That would need to be escaped, i.e. \.