T.R | Title | User | Personal Name | Date | Lines |
---|
9224.1 | | UNXA::KOPY | | Wed Mar 19 1997 08:44 | 17 |
| I use the following to strip <CR>
tr -d '\015'
If this is in a script called rm_cr.sh for example you could
do the following to strip <CR> from the file dos.txt:
rm_cr.sh < dos.txt > unix.txt
DOS files have a ^Z as the last line, this should also be removed.
BTW, I find that doing an ftp with transfer mode set to ASCII
properly strips the carriage returns and ^Z automatically.
Hope this helps.
- Walt
|
9224.2 | vi, et. al. can do this too | NETRIX::"[email protected]" | Farrell Woods | Wed Mar 19 1997 19:08 | 12 |
| vi will read the file and display the carriage returns as ^M's. You
can nuke these with this one-liner:
:s/^V^M$//
You'll be left at the bottom of the file, positioned just where you
would want to zap the ^Z. Note that the ^V^M sequence above is ctrl-V
and ctrl-M.
-- Farrell
[Posted by WWW Notes gateway]
|
9224.3 | close to what I use | VAXCPU::michaud | Jeff Michaud - ObjectBroker | Wed Mar 19 1997 20:07 | 9 |
| > :s/^V^M$//
I usually add a g to the end of this and get rid of the $ at the
end of the pattern string, ie:
:s/^V^M//g
this gets rid of all carriage-returns even when there are multiple
ones on a line (some things embed more than one).
|
9224.4 | Not doing the entire file | SWAM1::POIANI_MI | | Thu Mar 20 1997 11:27 | 6 |
| I am trying the VI approach... thanks for all this help folks... but
this is only stripping out ^M from the line on I'm on, it does not go
through the entire file. What could be the cause? 4.0b unix using the
c-shell.
Mike P.
|
9224.5 | dostounix | WASTED::map | Mark Parenti, Unix Engineering Group | Thu Mar 20 1997 11:43 | 6 |
| If you have SoftWindows installed you can use the provided dostounix() command
to strip the carriage returns (or the opposite unixtodos() to put them back).
Mark Parenti
UEG
|
9224.6 | The full command: | QUARRY::reeves | Jon Reeves, UNIX compiler group | Thu Mar 20 1997 11:44 | 16 |
| :1,$s/^V^M//g
The "1,$" does all lines; the "g" does all occurrences in each line.
Or use the vi-clone "vim" which has "textmode" that automatically detects a
DOS-format file; ":set notextmode" will make it write the file in UNIX format.
Or use the tr command mentioned earlier; from within vi, you can invoke it
1G!Gtr -d '\015'
Explanation: 1G goes to the top of the file. !G filters the entire file
through the following command.
Like most simple text processing problems, there are an almost infinite
number of ways to do the task in UNIX.
|
9224.7 | :%s/^V^M//g | UNIFIX::HARRIS | Juggling has its ups and downs | Thu Mar 20 1997 13:49 | 5 |
| vi command to remove ^M from a file
:%s/^V^M//g
Bob Harris
|
9224.8 | What about col(1)... | ADISSW::TENHAVE | | Fri Mar 21 1997 07:52 | 15 |
|
How about the col(1) command. It works great at
fixing those ugly ^M's.
Just do this...
col -b < file_to_be_fixed > new_fixed_file
Give it a shot right, from your unix prompt.
The file names may need to be different, but
the mv command can restore the original name.
Tim
|
9224.9 | this has one potential problem | NETRIX::"[email protected]" | Farrell Woods | Fri Mar 21 1997 09:03 | 28 |
| Our version of col will make other changes to the file (from col(1)):
...
-h [Digital] Compresses spaces into tabs. This is the default.
...
Moreover you can't turn this "feature" off. The -h flag doesn't appear
to actually do anything. (Perhaps the manual page should have added
the phrase "see figure 1".) :-)
This compression of spaces may or may NOT be desireable...
> col -b < file_to_be_fixed > new_fixed_file
> The file names may need to be different...
The file names WOULD need to be different. When you redirect stdout to
a file, the shell first truncates that file to zero length if it already
exists. So foo <input_file >input_file will wipe out input_file.
-- Farrell
[Posted by WWW Notes gateway]
|
9224.10 | flip it! | DECC::SULLIVAN | Jeff Sullivan | Tue Mar 25 1997 18:09 | 14 |
| There is a public domain flip program (source available from gatekeeper) that
does the flip from UNIX to DOS and DOS to UNIX. I've used it on every UNIX box
I've ever worked on and have never had a problem with it.
I have the source code on my UNIX machine and also on my PC at home. When
transferring files between the two (via mtools, zip or whatever), all you need
to do is flip it to your host environment (flip -u == "to unix", flip -m == "to
msdos"). Note that you don't need to use the annoying "/" as the switch
delimiter, even when on DOS.
See http://ftp.digital.com/cgi-bin/grep-index?flip
I selected "/pub/usenet/comp.sources.reviewed/volume7/flip.Z"
-Jeff
|
9224.11 | script.tidy | PERFOM::HENNING | | Tue Apr 01 1997 08:16 | 16 |
| UNIX POWER TOOLS gave me the following which is in my bin directory as
script.tidy and invoked as
script.tidy <mumble.in >mumble.out
#!/bin/sh
# Public domain.
# Put CTRL-M in $m and CTRL-H in $b
# Change \010 to \177 if you use DEL for erasing
eval `echo m=M b=H | tr 'MH' '\015\010'`
exec sed "s/$m\$//
:x
s/[^$b]$b//
t x" $*
|