Solved

Some thing to replace sed

Posted on 2001-07-16
7
374 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

816 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

12 Experts available now in Live!

Get 1:1 Help Now