Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-04-2017, 08:00 AM
|
#1
|
Member
Registered: Apr 2017
Distribution: Artix
Posts: 345
Rep: 
|
How does -b option in sed program perform usefully
How is the usage of -b option in sed, stream editor utility. I've been trying to find & replace a unicode text inside binary data. Which are sed's options and its command line would be to perform correct result.
For example the text 'collon' is among the binary, i.e invisible characters, and would be replaced with 'period'. So hex illustration looks like:
0 1 2 3 4 5 6 7 8 9 a b c d e f
09 29 0d 0a 63 00 6f 00 6c 00 6c 00 6f 00 6e 00 ....collon
...
... so on
Expected to become:
09 29 0d 0a 70 00 65 00 72 00 69 00 6f 00 64 00 ....period
What should I do, anyone please help me... many thanks in advance
Last edited by BudiKusasi; 04-04-2017 at 08:06 AM.
|
|
|
04-04-2017, 10:14 AM
|
#2
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
I've not used bbe which is a binary file editor replacement for sed. Usually when I manipulate binary files, I write a program to do so.
Either case, sed does do binary format, and I'm unsure, but there are also awk and tr commands which likely will do the same.
The issue is how to represent the binary characters, using printable ASCII, because you have to type something using escape clauses to identify the binary, or hex sequences you intend to find, edit, and replace. I believe the notation is \x prior to the number.
Have you managed to write any starting commands to find the sequence or sequences you are looking to identify for changes?
|
|
|
04-05-2017, 03:13 AM
|
#3
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
Looking at the man page, I don't think -b does what you think
Code:
-b
--binary
This option is available on every platform, but is only effective where
the operating system makes a distinction between text files and binary
files. When such a distinction is made—as is the case for MS-DOS, Windows,
Cygwin—text files are composed of lines separated by a carriage return and
a line feed character, and sed does not see the ending CR. When this option
is specified, sed will open input files in binary mode, thus not requesting
this special processing and considering lines to end at a line feed.
However, this page gives a detailed example of how to do what you want
https://everydaywithlinux.blogspot.c...-with-sed.html
Last edited by chrism01; 04-05-2017 at 03:14 AM.
|
|
1 members found this post helpful.
|
04-05-2017, 03:33 AM
|
#4
|
Member
Registered: Apr 2017
Distribution: Artix
Posts: 345
Original Poster
Rep: 
|
Thank you much , I do appreciate. I'm looking the page up..
|
|
|
All times are GMT -5. The time now is 10:18 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|