MarkLoveExEx
asked on
Java "sed" substitute command
Taking the following linux sed command:
sed 's/Q3A01RAD/MPM01 /' name > temp.file
What would be an equivalent way to accomplish this using Java code?
sed 's/Q3A01RAD/MPM01 /' name > temp.file
What would be an equivalent way to accomplish this using Java code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like this will get you started:In point of fact, you posted something implementing
's/Q3A01RAD/MPM01 /g'
To implement the given pattern, you'd need String.replaceFirst
Good catch CEHJ!
Doug
Doug
ASKER
Jim Cakalic -- I like the idea of using unix4j. However, I'm trying to figure out how to get it in my RedHat Eclipse IDE. Is there a compiled jar out there somewhere that I can add to my build path to get access to the functionality and have intellesense to help me formulate the syntax?
ASKER
Would you trust this site to get the unix4j jars?
http://www.java2s.com/Code/Jar/u/unix4j.htm
I would assume I would just add those to my class path...
http://www.java2s.com/Code/Jar/u/unix4j.htm
I would assume I would just add those to my class path...
ASKER
ASKER
Ok. I figured out how to use unix4j in my java code. Unfortunately, the file that I am attempting to use as input is a BINARY file. Command-line sed worked on my binary file, but the unix4j routine seems to have trouble with it (the binary file got larger/corrupted. Any ideas?
sed is normally used on text files (it works line-wise) so the Java implementation might not expect to have to be able to work with binary files
ASKER
CEHJ -- yes, I am very lucky that sed works on these particular binary files that I apply it on.
I'm not sure you can rely on the continuance of that
Open in new window
Doug