Solved

Some thing to replace sed

Posted on 2001-07-16
7
372 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

864 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