Hello Damian,
Thankyou ever so much for that perl script :-). I shall test it on my
laptop. I had written a similar utility in sed and awk, but it looks as
though your perl one is much quicker.
I really should start programming in perl again.
Thanks Again,
Thomas Adam
Linux Co-ordinator at The Purbeck School (Network Support)
Purbeck School,
WAREHAM,
Dorset,
www.purbeck.dorset.sch.uk
----- Original Message -----
From: Damian Counsell
Thomas!
Is this any use?
#! /usr/local/bin/perl
# dos2unix.pl by David Efflandt
# Modification of script from "Learning perl" p.353 # O'Reilly & Associates, Inc. # # Run after transfering text files from DOS to UNIX system. # Strips carriage returns from DOS files for use UNIX. # Transfers file permissions to new file (except suid bit). # # Usage:\tdos2unix.pl FILELIST # where FILELIST = one or more filenames # # If you edit this file in DOS you can run it on itself by typing: # perl dos2unix.pl dos2unix.pl # # Modify variables below for other search and replace functions. $find = "\r"; # find this $sub = undef; # substitute with this $rm_bak = 1; # remove old file after conversion: 0 = no, 1 = yes
while (<>) { if ($ARGV ne $oldargv) { ($dev,$ino,$mode,$nlink,$uid,$gid) = stat($ARGV); $backup = $ARGV . '.bak'; rename($ARGV, $backup); open (ARGVOUT, ">$ARGV"); chmod $mode, $ARGV; select(ARGVOUT); $oldargv = $ARGV; } s/$find/$sub/; } continue { print; if (eof) { print STDOUT "Converted: $oldargv\n"; unlink $backup if $rm_bak; } } select(STDOUT);
or this?
#!/bin/sh
es=1 if [ $# -eq 0 ] ; then exec tr -d '\015\032' elif [ ! -f "$1" ] ; then echo "Not found: $1" 1>&2 else for f in "$@" ; do if tr -d '\015\032' < "$f" > "$f.tmp" ; then if cmp "$f" "$f.tmp" > /dev/null ; then rm -f "$f.tmp" else touch -r "$f" "$f.tmp" if mv "$f" "$f.bak" ; then if mv "$f.tmp" "$f" ; then rm -f "$f.bak" es=$? echo " converted $f" else rm -f "$f.tmp" fi else rm -f "$f.tmp" fi fi else rm -f "$f.tmp" fi done fi
exit $es
all the best
Damian
n6tadam wrote:
Dear List,
I am trying to use 'dos2unix', but I am finding that each time I try it, I get the following error message:
recode: /doc.txt failed: Ambiguous output in CR-LF..data
Does anyone know what causes this, and how I fix it.
In fact, the command 'dos2unix', is a shell alias, for the following:
'recode ibmpc..lat1'
This is doing my head in!! I am very tempted to write a sed script instead, but I thought I'd ask the list first!!
Regards,
Thomas Adam
Please note that the content of this message is confidential between the original sender and the intended recipient(s) of the message. If you are not an intended recipient and/or have received this message in error, kindly disregard the content of the message and return it to the original sender.
If you have any complaints about this message please reply to: office@purbeck.dorset.sch.uk
The Purbeck School E-Mail server running: users.purbeck.dorset.sch.uk
-- To unsubscribe, e-mail: suse-linux-uk-schools-unsubscribe@suse.com For additional commands, e-mail: suse-linux-uk-schools-help@suse.com
-- Damian COUNSELL http://www.icr.ac.uk/cmb/bioinformatics/ CMB Bioinformatics phone: +44 020 7352 8133 x5226 Institute of Cancer Research direct: +44 020 7878 3850 London SW3 6JB fax: +44 020 7351 3325
-- To unsubscribe, e-mail: suse-linux-uk-schools-unsubscribe@suse.com For additional commands, e-mail: suse-linux-uk-schools-help@suse.com
Please note that the content of this message is confidential between the original sender and the intended recipient(s) of the message. If you are not an intended recipient and/or have received this message in error, kindly disregard the content of the message and return it to the original sender. If you have any complaints about this message please reply to: office@purbeck.dorset.sch.uk The Purbeck School E-Mail server running: users.purbeck.dorset.sch.uk