WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Need help with a scripting problem  (Read 2160 times)

Offline PingPing

  • Jr. Member
  • **
  • Posts: 94
Need help with a scripting problem
« 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.

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: Need help with a scripting problem
« Reply #1 on: June 18, 2009, 02:20:59 PM »
You can use sed with something like (untested)
Code: [Select]
sed -i 's/^#\(rest_of_line_to_search_for\)$/\1/' myfile

Offline PingPing

  • Jr. Member
  • **
  • Posts: 94
Re: Need help with a scripting problem
« Reply #2 on: June 19, 2009, 10:03:50 AM »
Thanks.  I'll have to do some more research on this 'sed' command.  It looks pretty nifty.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Need help with a scripting problem
« Reply #3 on: June 19, 2009, 01:57:55 PM »
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.
« Last Edit: June 19, 2009, 03:19:43 PM by danielibarnes »

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: Need help with a scripting problem
« Reply #4 on: June 19, 2009, 03:05:40 PM »
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. \.