LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 04-04-2017, 08:00 AM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Debian (MX)
Posts: 198

Rep: Reputation: Disabled
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.
 
Old 04-04-2017, 10:14 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,354
Blog Entries: 13

Rep: Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411
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?
 
Old 04-05-2017, 03:13 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,873

Rep: Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600
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.
Old 04-05-2017, 03:33 AM   #4
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Debian (MX)
Posts: 198

Original Poster
Rep: Reputation: Disabled
Thank you much , I do appreciate. I'm looking the page up..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to get sed not to perform edits on the first line asandybox Programming 6 08-31-2012 08:35 AM
Program to perform loopback test on serial port sacbravo Linux - Newbie 6 12-16-2011 09:49 PM
Sed: perform replacement only on even-numbered lines? kmkocot Linux - Newbie 3 07-20-2010 01:27 PM
C program to perform an operation continuously until user presses a key ananth86coolguy Linux - Newbie 4 03-13-2009 09:59 AM
unable to perform airthmetic calculation on value extracted by 'sed' command kamlesh_kmr Programming 6 12-01-2008 08:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration