Solved

Some thing to replace sed

Posted on 2001-07-16
7
370 Views
Last Modified: 2013-12-27
I have a file that has ascii and binary data (its actually a postscript file). I need to translate some of the string values at the beginning of the job.

I thought it would be easy

sed -e 's/123456/789012/' < input > output

The translation works correctly but the file is a different size.
I believe this is because of the binary data and inclusion of nulls.

If i try to edit the file in vi, it says line too long.

The file will edit successfully with dtpad.

Is there a version of sed that will handle the binary data and nulls or is there some other utility


 
0
Comment
Question by:markhardisty
7 Comments
 
LVL 3

Expert Comment

by:interiot
ID: 6286043
vim (Vi Improved) has support for longer lines, as well as binary editing.  See http://www.vim.org/html/editing.html#edit-binary

0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 6287679
If the file contains binary data, then it's not PostScript.  Maybe it's PDF or Encapsulated PostScript.
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6288648
look for sed with od -cx file
and after
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Accepted Solution

by:
shanechambers earned 100 total points
ID: 6289667
Perl might work better;
This will change 'file' inplace, while creating a 'file.orig' of the backup;

perl -p -i.orig -e's/123456/789012/' file
(drop the '.orig' after the -i if you don't want a backup)

An inline version of this would be;
cat file | perl -p -i -e's/123456/789012/'

Note this time I specified no backup copy was to be kept.

Just a suggestion.
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6289833
1. od -cx file >file1
2. sed -e 's/123456/789012/' < file > file2
3. od -cx file2 >file3
4. diff file1 file3
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6289835
1. od -cx file >file1
2. sed -e 's/123456/789012/' < file > file2
3. od -cx file2 >file3
4. diff file1 file3
0
 

Author Comment

by:markhardisty
ID: 6290407
Thanks every one:

Ok re the postscript comment it is an EPSF file, in fact a DCS master file with a binary preview

Vim seems a good option (took ages to download and then needed lots of extra librarys in place,) but it will edit the file, i havent had a chance to run it inline from a script though.

Im not sure i understand how the od example fixes the problem. Will try it a few more times to see if i can work it out

but the neatest and simplest is the perl solution so that gets the vote..

Thanks again.. This has dug me out of a mess
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now