Friday, 15 June 2012

regex - sed: find and replace a string (with characters like $ and space) in a binary file -


I have a file, where tail = 390 $ 0> $ Outname . I have to find this line and call it tail -n +390 $ 0> $ Outname . I am trying to do this with sed -

  sed -i -e '/ tail +390 \ $ 0 & gt; \ $ Outname / tail-n +390 \ $> \ $ Outname 'file.bin;  

and

  sed -i -e 's / tail \ +390 \ \ $ 0 \ & gt; \ \ $ Outname / tail \ -n \ +390 \ \ $ \ & gt; \ $ Outname 'file.bin;  

The file I am trying to modify is a binary file.

But I can not work it, any sign would be appreciated.

You only have to add a / since your SAD syntax is incorrect. It is like s / search / replace but it should be s / search / replace / alternate-modifiers .

  sed -i 's / tail +390 \ $ 0 & gt; \ $ Outname / Tail-N +390 \ $ 0 & gt; \ $ Outname / 'file  

Example:

  $ echo tail +390 $ 0> $ Outname '| Sed 's / tail +390 \ $ 0 & gt; \ $ Outname / Tail-N +390 \ $ 0 & gt; \ $ Outname / 'tail- n +390 $ 0 & gt; $ Outname  

No comments:

Post a Comment