|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
||||
|
||||
|
Need to replace odd character in file uploaded from windows to unix
I'm developing some java apps in Eclipse on Win2k, and when I scp the java files to the unix box, there's an odd character (^M) at the end of each line of the java program.
I've removed these characters manually, but it's a huge pain the butt, and some of these programs can be 1000+ lines. Is there a way to globally replace this character? I tried Code:
g/^M/s// /g and g/^M/s//REPLACEME/g but they didn't work. Here's an example of what it looks like: Code:
import java.util.Properties;^M
import javax.mail.*;^M
import javax.mail.internet.*;^M
^M
import java.sql.*;^M
import java.util.*;^M
^M
public class OneStopReport ^M
{^M
^M
^M
public static void main(String[] args) throws ClassNotFoundException^M
{^M
//OneStopReport.loadOnestopDatabase();^M
OneStopReport.generateOneStopReport();^M
} ^M
Last edited by StevenC : May 13th, 2004 at 01:04 PM. |
|
#2
|
||||
|
||||
|
There are different ways to handle this:
1. Use ftp instead of scp and ftp the files over in ASCII mode. This will automatically remove the ^M characters. 2. Do a whereis dos2unix to see if dos2unix is installed on your system. If so, simply type: dos2unix *.java and it'll convert your java files. 3. If you don't have dos2unix, either consider installing it or roll out your own dos2unix script. See http://forums.devshed.com/showthrea...21944&forumid=6 fpr a one-liner perl script that does it.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
||||
|
||||
|
Thanks, but it doesn't seem any of those will work.
FTP isn't enabled on any of our machines. whereis doesn't even seem to work. (AIX 5.0.1.1) Code:
$ whereis dos2unix ksh: whereis: not found And I highly doubt perl is installed on any of our unix boxes. Is it possible to do it with a shell script? Or is there a java way to do that? |
|
#4
|
||||
|
||||
|
Use sed or perhaps write a java program to remove \r from files.
|
|
#5
|
||||
|
||||
|
Java program sounds good, but whats sed?
Ya, I'm a unix n00b. ![]() Last edited by StevenC : May 17th, 2004 at 01:07 PM. |
|
#6
|
||||
|
||||
|
Aha! The box does have dos2unix.
The command is which on our box (Maybe an AIX thing), not whereis. *.java didn't work though. Had to specify each file name manually. |
|
#7
|
||||
|
||||
|
in vi:
:%s/\r\n/\n/g christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#8
|
||||
|
||||
|
Quote:
lol - I'll have a puff when you're done with that ![]() christo |
|
#9
|
||||
|
||||
|
>> *.java didn't work though. Had to specify each file name manually.
Are all the *.java files in the current directory or not. If they are in subdirectories, then *.java won't work and you'll have to specify the path name. Alternatively, you could use something like this: find . -type f -name "*.java" | xargs dos2unix This will recursively find all the java files starting from the current directory and run dos2unix on each one. Christo, one of these days I might actually do it. Gotta keep my java skillz up you know . |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Need to replace odd character in file uploaded from windows to unix |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|