Solved

Some thing to replace sed

Posted on 2001-07-16
7
375 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

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.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…

828 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